实例讲解iOS应用开发中使用UITableView创建自定义表格

2020-01-14 19:52:03王冬梅

{
    return [news_MArray count];
}
4.自定义cell上控件

 

    在cellForRow方法中if(cell==nil)前

 

复制代码
/*****自定义cell******/
newsModel *model    = [news_MArray objectAtIndex:indexPath.row];
 
UIImageView *   image_view;     //1.添加imageView
UILabel *       title_label;    //2.添加标题Label
UILabel *       summary_label;  //3.添加摘要Label
UILabel *       replyNo_label;  //4.添加跟帖数量Label
UIButton  *     extra_view;     //5.属于专题或者独家报道,进行标记
/********************/
    在if(cell==nil)内
复制代码
/*****自定义cell******/
         
        //1.添加imageView
        CGRect imageViewF   = CGRectMake(5, 5, 85, 65);
        image_view          = [[UIImageView alloc] initWithFrame:imageViewF];
        [cell addSubview:image_view];
         
        //2.添加标题Label
        CGRect titleLabelF  = CGRectMake(95, 5, 230, 24);
        title_label         = [[UILabel alloc] initWithFrame:titleLabelF];
        title_label.font    = [UIFont systemFontOfSize:16];//字体大小
        [cell addSubview:title_label];
         
        //3.添加摘要Label
        CGRect summaryLabelF  = CGRectMake(97, 27, 210, 40);
        summary_label         = [[UILabel alloc] initWithFrame:summaryLabelF];
        summary_label.font    = [UIFont systemFontOfSize:12];    // 字体大小
        summary_label.textColor     = [UIColor darkGrayColor];  // 文字颜色
        summary_label.numberOfLines = 2;