自定义约束sd_autolayout

在这里插入图片描述

.h 自定义一个表格

#import <UIKit/UIKit.h>
#import "Model.h"
NS_ASSUME_NONNULL_BEGIN

@interface jokeTableViewCell : UITableViewCell
@property(nonatomic,strong)UILabel *labelI;
@property(nonatomic,strong)UILabel *labelII;
-(void)cellSetValue:(Model * )modelcell;
@end

.m

#import "jokeTableViewCell.h"

@implementation jokeTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self.contentView addSubview:self.labelI];
        [self.contentView addSubview:self.labelII];
    //约束
    self.labelI.sd_layout
    .leftSpaceToView(self.contentView, 15)
    .topSpaceToView(self.contentView, 10)
    .rightSpaceToView(self.contentView, 20)
    .heightIs(100);


    self.labelII.sd_layout
    .leftEqualToView(self.labelII)//距离左和上一个label对齐
    .topSpaceToView(self.labelII, 80)//距离上一个label80
    .rightSpaceToView(self.contentView, 20)
    .heightIs(40);
    [self setupAutoHeightWithBottomView:self.labelII bottomMargin:20];
    
    }
    return self;
}
-(UILabel *)labelI
{
    // 判断 如果没有内容 就创建
    if (!_labelI) {
        _labelI = [[UILabel alloc]init];
        // 设置 字体
        _labelI.font = [UIFont systemFontOfSize:15];
        _labelI.textColor = [UIColor blackColor];
        
    }
    return _labelI;
}
-(UILabel *)labelII
{
    // 判断 如果没有内容 就创建
    if (!_labelII) {
        _labelII = [[UILabel alloc]init];
        // 设置 字体
        _labelII.font = [UIFont systemFontOfSize:20];
        _labelII.textColor = [UIColor redColor];
        _labelI.numberOfLines = 0;
    }
    return _labelII;
}
-(void)cellSetValue:(Model * )modelCell
{
    self.labelI.text = modelCell.content;
    self.labelII.text = modelCell.updatetime;
   
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值