iOS开篇——UI之UITableView 自定义Cell

创建一个继承于UITableViewCell的类

重写父类方法

1 //先重写父类方法
2 - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
3     if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
4         [self customCell];
5     }
6     return self;
7 }

再实现customCell方法

- (void)customCell{
//    _label = [[UILabel alloc]initWithFrame:CGRectMake(50, 5, 25, 20)];
//    _label.text = @"全天";
//    _label.textColor = [UIColor blackColor];
//    _label.adjustsFontSizeToFitWidth = YES;
//    //
//    
//    _view = [[UIView alloc]initWithFrame:CGRectMake(80, 1, 1, 42)];
//    _view.backgroundColor = [UIColor darkGrayColor];
//    _view.alpha = 0.3;
//    [self.contentView addSubview:_view];
//    [self.contentView addSubview:_label];
//    
//    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(85, 7.5, 10, 10)];
//    view.backgroundColor = [UIColor redColor];
//    view.alpha = 0.7;
//    [self.contentView addSubview:view];
//    
//    _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 5, 100, 15)];
//    _titleLabel.font = [UIFont boldSystemFontOfSize:14];
//    _titleLabel.textColor = [UIColor darkTextColor];
//    
//    [self.contentView addSubview:_titleLabel];
    
    
    
    _label = [[UILabel alloc]initWithFrame:CGRectMake(30, 10, 50, 24)];
    _label.textColor = [UIColor blackColor];
    
    [self.contentView addSubview:_label];
    
//    _theSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(self.contentView.frame.size.width-30, 7, 30, 10)];
//    
//    [self.contentView addSubview:_theSwitch];
    
    
    
}

 

转载于:https://www.cnblogs.com/gwkiOS/p/5027910.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值