开发者社区 问答 正文

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

展开
收起
爵霸 2016-03-06 08:28:14 2599 分享 版权
1 条回答
写回答
取消 提交回答
  • cell.textLabel.textColor=[UIColor redColor];
    cell.textLabel.highlightedTextColor=[UIColor grayColor];中的textLabel 不是你定义的属性值的label,textLabel cell 默认的一个label

    2019-07-17 18:53:54
    赞同 展开评论
问答地址: