Masonry自动计算行高

 Masonry自动计算行高:

@interface ChatTableViewCell()


@property (weak,nonatomic) IBOutletUILabel *chatLabel;

@property (weak,nonatomic) IBOutletUIActivityIndicatorView *activityView;

@property (weak,nonatomic) IBOutletUIButton *sendButton;


@end

@implementation ChatTableViewCell


-(void)layoutSubviews

{

    [superlayoutSubviews];

//---------------------------------设置最大约束尺寸

    self.chatLabel.preferredMaxLayoutWidth = kScreenWidth -30;

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

    if (self = [superinitWithStyle:style reuseIdentifier:reuseIdentifier]) {

        [selfconfigSubviews];

        self.selectionStyle =UITableViewCellSelectionStyleNone;

    }

    returnself;

}

-(void)configSubviews

{

//展示文本

    UILabel * label = [[UILabelalloc]init];

    self.chatLabel = label;

    self.chatLabel.numberOfLines = 0;

    [self.contentViewaddSubview:label];

    WS(ws);

//对文本添加约束

    [self.chatLabelmas_makeConstraints:^(MASConstraintMaker *make) {

//左边 上边各留5各间距,右边由上面设置的最大约束进行设置约束

        make.left.top.equalTo(ws.contentView).offset(5);

//-----------------------------------重点:将最下面的控件与contentView进行约束,否则行高不准确

        make.bottom.equalTo(ws.contentView).offset(-5);

    }];

//小菊花

    UIActivityIndicatorView * indicationView = [[UIActivityIndicatorViewalloc]init];

    indicationView.color = [UIColorgrayColor];

    self.activityView = indicationView;

    [self.contentViewaddSubview:indicationView];

//对小菊花添加约束

    [self.activityViewmas_makeConstraints:^(MASConstraintMaker *make) {

//水平居中

        make.centerY.equalTo(ws.contentView);

//大小

        make.size.mas_equalTo(CGSizeMake(15,15));

//在文本的右侧 留5个间距

        make.left.equalTo(ws.chatLabel.mas_right).offset(5);

    }];



//buttion与菊花的位置全都相同

    UIButton * button = [[UIButtonalloc]init];

    button.backgroundColor = [UIColorredColor];

    [button setImage:[UIImageimageNamed:@"blueArrow"]forState:UIControlStateNormal];

    [self.contentViewaddSubview:button];

    self.sendButton = button;

    [self.sendButtonmas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.equalTo(ws.contentView);

        make.size.mas_equalTo(CGSizeMake(15,15));

        make.left.equalTo(ws.chatLabel.mas_right).offset(5);

    }];



//----------------------------------重点:设置cell的contentView 与 cell四条边对齐

    [self.contentViewmas_makeConstraints:^(MASConstraintMaker *make) {

        // 重点代码:contentView4条边和self对齐

        make.top.left.right.bottom.mas_equalTo(self);

    }];

    

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值