cell的定制界面


1.继承自UITableViewCell类,创建自定义cell类
1.1添加需要显示的属性字段

@interface MyTableViewCell ()

{

    //保存应用程序图标

    UIImageView *_iconView;

    //保存公司的名称

    UILabel *_publishView;

    //应用程序名称

    UILabel *_nameView;

    //保存价格

    UILabel *_priceView;

    //评分的人数

    UILabel *_numRatingsView;

    //评分的分数

    UIView *_ratingView; 

}

@end

1.2在类的初始化方法中定义初始化属性字段并添加到自身的contentView视图上

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

        //1.创建应用图标

        _iconView = [[UIImageView alloc]init];

        _iconView.frame = CGRectMake(5, 5, 60, 60);

        [self.contentView addSubview:_iconView];

        //2.创建公司名称

        _publishView = [[UILabel alloc]init];

        _publishView.frame = CGRectMake(90, 5, 250, 20);

        [self.contentView addSubview:_publishView];

        //3.应用名称

        _nameView = [[UILabel alloc]init];

        _nameView.frame = CGRectMake(90, 30, 200, 25);

        [self.contentView addSubview:_nameView];

        //4.价格

        _priceView = [[UILabel alloc]initWithFrame:CGRectMake(300, 30, 60, 25)];

        [self.contentView addSubview:_priceView];

        //5.评分分数

        _ratingView = [[UIView alloc]initWithFrame:CGRectMake(90, 65, 100, 23)];

        _ratingView.backgroundColor = [UIColor lightGrayColor];

        [self.contentView addSubview:_ratingView];

        //6.评分人数

        _numRatingsView = [[UILabel alloc]initWithFrame:CGRectMake(200, 65, 100, 20)];

        [self.contentView addSubview:_numRatingsView];

    }

    return self;

}



2.在控制器的表视图的数据源协议方法的定义cell方法中实例化自定义类,并赋值相应的数据

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    NSString *cellID = @"cellID";

    //创建自定义cell

    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];

    if (cell == nil) {

        cell = [[MyTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];

    }

    //设置要显示的内容

    //1.对自定义cell的相关属性赋值数据

    NSDictionary *dict = [self.arrayData objectAtIndex:indexPath.row];

    cell.iconView.image = [UIImage imageNamed:[dict objectForKey:@"Icon"]];

    cell.publishView.text = [dict objectForKey:@"Publisher"];

    cell.priceView.text = [dict objectForKey:@"Price"];

    cell.nameView.text = [dict objectForKey:@"Name"];

    cell.numRatingsView.text = [[dict objectForKey:@"NumRatings"] stringValue];   

    return cell;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值