ios - 使用 UIAppearance 更改选定的单元格背景颜色

标签 ios objective-c uitableview uicolor uiappearance

我需要为我的应用程序中的所有单元格更改选定的单元格背景颜色。据我所知,有一种方法可以使用 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/

相关文章:

ios - fatal error : Index out of range - UITableViewController - How to handle/catch this error Swift

iphone - 自定义 UITableViewCell 中的 NSNotification 观察者?

ios - 从 iOS 设备解压 PKCS7 负载(MDM 注册)

ios - 在 iOS 上的图像中查找非透明填充的 CGRect

ios - 为什么构建编译失败并且无法识别 *pch 中的 __OBJC__ 宏?

objective-c - NSScrollView 叠加小牛

iphone - 在 UITableView 上方增加 UIView 的高度

ios - React Native - React Native 可以做什么,不可以做什么?

iOS curl : unable to get local issuer certificate

ios - Alamofire:无法调用下载