欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Masonry错误记录

程序员文章站 2022-05-31 11:38:50
...

约束要素要配对使用例如

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

而不能写成

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

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