我需要为我的应用程序中的所有单元格更改选定的单元格背景颜色。据我所知,有一种方法可以使用 UIAppearance
为此目的的协议(protocol)。是否可以通过 UITableViewCell
的类别来实现这一点? ?
最佳答案
使用外观代理,您可以为所有单元格着色。不知道您是否可以针对特定类别。
要进行着色,请将以下代码放入您的 AppDelegate.m 文件中:
把 [self customCellBackground];
在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions
最后的某个地方:
- (void)customCellBackground {
UIView *cellBackgroundView =[[UIView alloc] init];
cellBackgroundView.backgroundColor = [UIColor blackColor];
[[UITableViewCell appearance] setSelectedBackgroundView:cellBackgroundView];}
关于ios - 使用 UIAppearance 更改选定的单元格背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22476819/