继承UITableViewCell,并定义属性。
@interface MyTableViewCell : UITableViewCell
@property(nonatomic,strong)UIImageView *icon;
@property(nonatomic,strong)UILabel *name;
@property(nonatomic,strong)UILabel *actor;
@property(nonatomic,strong)UILabel *time;
@end
重写初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
if(self){
self.icon=[[UIImageView alloc]init];
[self.contentView addSubview:self.icon];
self.name=[[UILabel alloc]init];
[self.contentView addSubview:self.name];
self.actor=[[UILabel alloc] init];
[self.contentView addSubview:self.actor];
self.time=[[UILabel alloc]init];
[self.contentView addSubview:self.time];
}
return self;
}
设置控件的信息
-(void)layoutSubviews{
[super layoutSubviews];
self.imageView.frame=CGRectMake(10, 10, 50, 50);
self.name.frame=CGRectMake(70, 10, 260, 20);
self.actor.frame=CGRectMake(70, 40, 260, 20);
self.time.frame=CGRectMake(70, 70, 260, 20);
}