美文网首页
Masonry错误记录

Masonry错误记录

作者: 我一不小心就 | 来源:发表于2018-04-17 16:36 被阅读0次

    约束要素要配对使用例如

    self.lanternSwitchBtn = [[UIButton alloc] init];
         [self.lanternSwitchBtn setImage:[UIImage imageNamed:@"ic_shut down"]
         forState:UIControlStateNormal];
         [self addSubview:self.lanternSwitchBtn];
         [self.lanternSwitchBtn makeConstraints:^(MASConstraintMaker *make) {
             make.right.equalTo(self.mas_right).offset(-19.0f);// 要素点
             make.centerY.equalTo(lanternIcon.mas_centerY);
             NSLog(@"width:%f======height:%f",switchImgSize.width,switchImgSize.height);
             make.size.mas_equalTo(CGSizeMake(switchImgSize.width, switchImgSize.height));
         }];
    

    而不能写成

    self.lanternSwitchBtn = [[UIButton alloc] init];
         [self.lanternSwitchBtn setImage:[UIImage imageNamed:@"ic_shut down"]
         forState:UIControlStateNormal];
         [self addSubview:self.lanternSwitchBtn];
         [self.lanternSwitchBtn makeConstraints:^(MASConstraintMaker *make) {
             make.right.equalTo(self.mas_trailing).offset(-19.0f);// 要素点
             make.centerY.equalTo(lanternIcon.mas_centerY);
             NSLog(@"width:%f======height:%f",switchImgSize.width,switchImgSize.height);
             make.size.mas_equalTo(CGSizeMake(switchImgSize.width, switchImgSize.height));
         }];
    

    虽然mas_right和mas_trailing要表达的意思是一样的,但是这种不配对的用法会导致崩溃,必须对应使用

    相关文章

      网友评论

          本文标题:Masonry错误记录

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