普通网友 2016-04-26 06:03 采纳率: 33.3%
浏览 1638
已结题

自定义UITableVIewCell为啥textColor颜色设置不生效了

//
// HQTableViewCell.m
// TableViewTest
//
// Created by hq on 16/4/26.
// Copyright © 2016年 hanqing. All rights reserved.
//

#import "HQTableViewCell.h"

@interface HQTableViewCell()

@property (weak, nonatomic) IBOutlet UILabel *label;

@end

@implementation HQTableViewCell

+(instancetype) tableViewCell:(UITableView *)tableView{

NSString *ID=@"cell";

HQTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];


if (cell==nil) {

    [tableView registerNib:[UINib nibWithNibName:@"cell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:ID];

    cell=[tableView dequeueReusableCellWithIdentifier:ID];

    **cell.textLabel.textColor=[UIColor redColor];

            cell.textLabel.highlightedTextColor=[UIColor grayColor];**

}

return cell;

}

-(void)setStr:(NSString *)str{

_str=str;

self.label.text=str;

}

  • (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state

}

@end

  • 写回答

7条回答 默认 最新

  • 朕就是这么帅 2016-04-26 06:41
    关注

    cell.textLabel.textColor=[UIColor redColor];
    cell.textLabel.highlightedTextColor=[UIColor grayColor];中的textLabel 不是你定义的属性值的label,textLabel cell 默认的一个label

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败