我在每行中都有一个大的自定义UITableView
和UILabels
,我想用黑色或绿色显示某些文本。在UItableViewCell中更改UILabel文本颜色
我从NSArray
供给NSString's
的细胞。假设我想用黑色显示30
索引中的NSString
。
我想这样的事情,但它不工作:
NSIndexPath *indexPathWithBlackText = [NSIndexPath indexPathForRow:30 inSection:[indexPath section]];
if (indexPath.row == indexPathWithBlackText.row) {
//Label with text in black
topLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
topLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];
} else {
//Label with text in green
topLabel.textColor = [UIColor colorWithRed:0.122 green:0.467 blue:0.255 alpha:1.00];
}
在正确的方向任何提示将非常感激。谢谢!
为什么不你如果(indexPath == indexPathWithBlackText)?在代码中你在做什么? –
我只是试图将黑色或绿色的文本标签分配到一个固定的位置,与提供单元格的NSArray中的索引相同。问题是,当我滚动UITableView其他文本也改变颜色,而不仅仅是我想要的行中的颜色,我认为这是由于UITableView动态绘图。 – Winston