普通网友 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

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料