首页 > 代码库 > IOS 标签按钮的选择
IOS 标签按钮的选择
typedef enum : NSUInteger { FLSearchLabelButInformation = 1000, //资讯 FLSearchLabelButBBs = 1001, //论坛 FLSearchLabelButMall = 1002, //商城 FLSearchLabelButMobile = 1003, //手机 } FLSearchLabelBut; - (void)creatleUI{ NSArray *dataArry = @[@"咨询", @"论坛", @"商城", @"手机"]; CGFloat deli_with = 50; for (int index = 0; index < dataArry.count; index++) { UIButton *butt = [UIButton buttonWithType:UIButtonTypeCustom]; butt.frame = CGRectMake(deli_with *index, 0, deli_with, CGRectGetHeight(self.frame)); butt.tag = FLSearchLabelButInformation + index; [butt setTitleColor:[UIColor colorWithString:@"#969696"] forState:UIControlStateNormal]; if(index==0){ [butt setTitleColor:[UIColor colorWithString:@"#262626"] forState:UIControlStateNormal]; } [butt setTitle:dataArry[index] forState:UIControlStateNormal]; butt.titleLabel.font = [UIFont systemFontOfSize:14.0f]; [butt addTarget:self action:@selector(onClickView:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:butt]; } } - (void)onClickView:(UIButton *)sender{ for(UIView *locateView in self.subviews){ if([locateView isKindOfClass:[UIButton class]]){ UIButton *locateButt = (UIButton *)locateView; [locateButt setTitleColor:[UIColor colorWithString:@"#969696"] forState:UIControlStateNormal]; } } [sender setTitleColor:[UIColor colorWithString:@"#262626"] forState:UIControlStateNormal]; if([_delegate respondsToSelector:@selector(onClickSearhbutt:)]){ [_delegate onClickSearhbutt:sender.tag]; } }
点击每个标签改变当前的颜色
本文出自 “雪花飞落满人间” 博客,请务必保留此出处http://smengxiang.blog.51cto.com/11204872/1860831
IOS 标签按钮的选择
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。