ios中自定义cell即列表的item

继承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中。
        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);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值