iOS 代码实现自定义TableView 自定义TableViewCell

iOS 代码实现自定义TableView 自定义TableViewCell

向cell.contentView添加自定义内容

    //image
    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"表单列表"]];
    image.frame = CGRectMake(kContentScaleFactor(30), (kContentScaleFactor(94) - image.height) / 2, image.width, image.height);
    
    //label
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(kContentScaleFactor(30 + 12) + image.width, (kContentScaleFactor(94) - kLabelHeight) / 2, kLabelWidth, kLabelHeight)];
    label.textAlignment = NSTextAlignmentLeft;
    [label setFont:[UIFont systemFontOfSize:kContentScaleFactor(30)]];
    [label setTextColor:[UIColor colorWithHex:0x323232 alpha:1]];
    label.tag = kLabelTag;
    [cell.contentView addSubview:image];
    [cell.contentView addSubview:label];

数据绑定

//=============绑定数值===============
    //从indexPath中获取行号
    NSUInteger row = indexPath.row;
    //NSDictionary *rowData = [self.rootTableList objectAtIndex:row];
    UILabel *name = (UILabel *)[cell.contentView viewWithTag:kLabelTag];
    //name.text = [rowData objectForKey:<#(nonnull id)#>]
    name.text = [self.rootTableList objectAtIndex:row];
    [name sizeToFit];
    return cell;


你可能感兴趣的:(iOS初学-2016,UITableView,UITableViewCell,ios,Objective-C)