自定义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

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

cell.textLabel 中的label是表格自带的一个label

cell.textLabel 中的label是表格自带的一个label<br>
图片说明
你设置的属性是:cell.label.text = [UIColor redColor];

系统总有一个textLabel,你把xib里的textLabel改个名吧

self.label.textColor = [UIColor redColor];

一个是系统的,一个是你自定义的;
改成cell.label.textColor = [UIColor redColor];

改成cell.label.text = [UIColor redColor];就可以了