IOS 标签按钮的选择

发布时间:2020-06-18 12:47:02 作者:大头狼小鬼
来源:网络 阅读:364
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];
    }
}

IOS 标签按钮的选择

点击每个标签改变当前的颜色

推荐阅读:
  1. iOS应用发布指南
  2. 疯狂ios讲义之疯狂打飞机(1)

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ios

上一篇:Goldengate monitor v11.1

下一篇:C#基础知识整理:基础知识(14) 数组

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》