话不多说直接上代码:
NSArray *array = @[@"1",@"2"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundColor:[UIColor purpleColor]];
[self.view addSubview:button];
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(0);
make.height.mas_offset(50);
make.right.mas_offset(0);
make.bottom.equalTo(self.view.mas_bottom).offset((-(array.count) * 20));
}];
童鞋们,你感觉会发生啥结果;
那就是button不会显示,因为array.count返回是无符号的,(-(array.count) * 20)返回结果仍然是无符号的,然后button就不会出现。
解决方案:
int num = array.count;
make.bottom.equalTo(self.view.mas_bottom).offset((-num * 20));
如有不对之处希望评论留言指出,谢谢!!!
网友评论