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];
    
    
    
}

 

posted @ 2015-12-07 23:46  GXcoder  阅读(279)  评论(0编辑  收藏  举报