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

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

        [cell addSubview:summary_label];
         
        //4.跟帖数量Label
        CGRect replyNoLabelF  = CGRectMake(210, 45, 95, 24);
        replyNo_label         = [[UILabel alloc] initWithFrame:replyNoLabelF];
        replyNo_label.font    = [UIFont systemFontOfSize:12];    // 字体大小
        replyNo_label.textColor     = [UIColor darkGrayColor];  // 文字颜色
        replyNo_label.textAlignment = NSTextAlignmentRight;      // 文字右对齐
         
        //5.专题extraView
        CGRect extraViewF       = CGRectMake(270, 50, 28, 14);
        extra_view              = [[UIButton alloc] initWithFrame:extraViewF];
        extra_view.titleLabel.font = [UIFont boldSystemFontOfSize:10];
        [extra_view setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
         
        // 普通新闻,只添加跟帖数量
        if (model.reportType==NEWSReportOrdinary) {
           [cell addSubview:replyNo_label];
        }
        // 专题新闻,添加专题标志,并添加跟帖数量
        else if(model.reportType == NEWSReportSpecial){
             
            // 设置背景色
            extra_view.backgroundColor = [UIColor colorWithRed:120.0/255.0 green:170.0/255.0 blue:245.0/255.0 alpha:1.0];
             
            [extra_view setTitle:@"独家" forState:UIControlStateNormal];// 设置标题
             
            [cell addSubview:extra_view];                               // 添加