【问题标题】:How do I change the font color in a tableview cell to a variable UIColor?如何将 tableview 单元格中的字体颜色更改为变量 UIColor?
【发布时间】:2012-01-04 16:38:09
【问题描述】:

我在这里添加颜色,但它没有反映在单元格中。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.textLabel.font =[UIFont systemFontOfSize:14];
    //cell.textLabel.textColor = theFontColor;//this does not work
    //cell.textLabel.textColor = [UIColor whiteColor];//this works
    // Configure the cell.

    [self configureCell:cell atIndexPath:indexPath];

    return cell;
}

编辑

configureCell 覆盖了颜色。抱歉,这是一个真正的菜鸟错误。

【问题讨论】:

  • 检查 -configureCell:atIndexPath: 是否没有覆盖您之前设置的颜色。假设设置了字体颜色,所描述的方法应该可以工作。
  • 感谢 Warkst 确认它应该可以工作,我跑过去发现虽然设置了字体颜色,但它首先运行了 cellForRowAtIndexPath 并导致了 NSInternalInconsistencyException。

标签: ios objective-c uitableview fonts colors


【解决方案1】:

您是否在某处将字体颜色定义为 UIColor

你应该这样做:

     UIColor *theFontColor = [UIColor colorWithRed:64.0f/255.0f green:58.0f/255.0f blue:43.0f/255.0f alpha:1.0f];

...然后使用它

【讨论】:

  • 我正在设置字体颜色,但只是在我尝试在 cellForRowAtIndexPath 中使用它之后。感谢您的帮助:)
猜你喜欢
  • 2011-09-23
  • 1970-01-01
  • 1970-01-01
  • 2019-12-07
  • 2011-12-24
  • 2013-03-15
  • 2011-10-23
  • 2014-07-15
  • 1970-01-01
相关资源
最近更新 更多