.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