iOS:在awakeFromNib中使用砌体对我来说不起作用

时间:2016-02-24 03:38:25

标签: ios objective-c xib masonry

这是代码

@interface ContactsViewCell ()

@property (nonatomic, weak) IBOutlet UILabel *nameLabel;
@property (nonatomic, weak) IBOutlet UILabel *numLabel;
@property (nonatomic, weak) IBOutlet UIButton *addBtn;

@end


@implementation ContactsViewCell

- (void)awakeFromNib {
    // Initialization code
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(12);
        make.height.mas_equalTo(20);
        make.right.mas_equalTo(-80);
    }];

    [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_left);
        make.top.mas_equalTo(self.nameLabel.bottom).offset(-4);
        make.width.equalTo(self.nameLabel.mas_width);
        make.height.equalTo(self.nameLabel.mas_height);
    }];

    [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(56);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(32);
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
}

但是单元格中所有这些子视图的框架在执行后没有改变,仍然是初始化状态。怎么修?

size in inspector

0 个答案:

没有答案