Masony 循环添加控件

释放双眼,带上耳机,听听看~!
__block UILabel *lastLabel = nil;
    WEAKSELF
    for (int i = 0; i < self.categoryArr.count; i++) {
        UILabel *label = [UILabel new];
        label.tag = 1000 + i;
        if (i == 0)
            label.textColor = kAppThemeColor;
        else
            label.textColor = kAppThemeWordColor;
        label.font = kAppThemeFont;
        label.text = [weakSelf.categoryArr objectAtIndex:i];
        label.userInteractionEnabled = YES;
        label.textAlignment = NSTextAlignmentCenter;
         UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionForCategory:)];
        [label addGestureRecognizer:recognizer];
        [self.scrollView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(57);
            make.height.mas_equalTo(32);
            make.top.equalTo(weakSelf.scrollView.mas_top);
            if (!lastLabel)
                make.left.equalTo(weakSelf.scrollView.mas_left);
            else
                make.left.equalTo(lastLabel.mas_right);
        }];
        lastLabel = label;
    }

 

人已赞赏
iOS文章

iOS Realm数据库使用

2019-10-29 10:44:09

iOS文章

OSAtomic原子操作

2019-10-29 11:41:06

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索