美文网首页
当Masonry遇到无符号类型

当Masonry遇到无符号类型

作者: 等一个最好的自己 | 来源:发表于2020-09-24 14:29 被阅读0次

    话不多说直接上代码:

    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));

    如有不对之处希望评论留言指出,谢谢!!!

    相关文章

      网友评论

          本文标题:当Masonry遇到无符号类型

          本文链接:https://www.haomeiwen.com/subject/fwwzyktx.html