繁体   English   中英

在自定义UITableViewCell中更改UILabel的颜色

[英]change color of UILabel in custom UITableViewCell

我在更改UILabel textColor属性时遇到一个小问题,它不会更改tableView didSelectRowAtIndexPath方法中的颜色我正在使用SubClassed和

我正在使用最新的XCode4 GM版本,并且想知道是否有人遇到类似的东西,或者可能是xcode版本中的错误

更新:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
  NSIndexPath *indexPath = [tableView indexPathForCell:(HSCustomCellTF *)[[textField superview] superview]];
  HSCustomCellTF *cell = (HSCustomCellTF *)[tableView cellForRowAtIndexPath:indexPath];
  cell.keyLBL.textColor = [UIColor redColor];
  cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"middleRowSelectedBG.png"]] autorelease];

  tableView.userInteractionEnabled = NO;

  return YES;
}

我想补充一点,我已经尝试了其他方法来获得结果,但是没有运气,我现在将尝试willDisplayCell方法,看看效果如何,感谢您的帮助。

而且backgroundView确实正确更改,所以我正在访问单元格

用这个 :

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    CustomCell *cell = (CustomCell*)[tableView cellForRowAtIndexPath:indexPath];

    cell.label.textColor = [UIColor whiteColor];

    return indexPath;
}
- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CustomCell *cell = (CustomCell*)[tableView cellForRowAtIndexPath:indexPath];

    cell.label.textColor = [UIColor darkGrayColor];

    return indexPath;
}

好的,我找到了答案,似乎当您使用自定义单元格时,您想编辑标签颜色,然后在tableViewCell的子类中,一旦删除了,就不要在layoutSubviews方法中设置该属性。该方法@gkchristopher回答的textColor属性是正确的,谢谢大家的帮助,希望这将对其他人有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM