UITableViewCell外观仅更改视图中当前的单元格

时间:2014-03-18 03:55:47

标签: ios uilabel uiappearance

使用UIAppearance,我正在更改Table View Cell的标签颜色。这样可以正常工作,但它只会对当前看到的细胞进行着色。视图外的所有单元格(未被看到)仍然是默认颜色(黑色)。

在摘要中,该方法仅更改当前正在查看的单元格,而不是视图中的单元格(滚动到视图外)。

这是我的UIAppearance代码:

[[UILabel appearanceWhenContainedIn:[_textLabel class], nil]
 setTextColor:[UIColor colorWithRed:(204.0f/255.0f) green:(204.0f/255.0f) blue:(204.0f/255.0f) alpha:1.0f]];

1 个答案:

答案 0 :(得分:0)

我猜你这里有拼写错误,_textLabel必须是UITableViewCell而不是UILabel

[[UILabel appearanceWhenContainedIn:[YourTableViewCell class], nil]
 setTextColor:[UIColor colorWithRed:(204.0f/255.0f) green:(204.0f/255.0f) blue:(204.0f/255.0f) alpha:1.0f]];

您可以在cellForRowAtIndexPath

中查看重复使用的单元格
static NSString *CellIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
   cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}