使用UIAppearance更改选定的单元格背景颜色 [英] Change the selected cell background colour using UIAppearance
问题描述
我需要更改应用中所有单元格的选定单元格背景颜色。据我所知,有一种方法可以使用 UIAppearance
协议。是否可以通过 UITableViewCell
的类别实现这一点?
I need to change the selected cell background colour for all the cells in my app. As I know there is a way to use UIAppearance
protocol for this purposes. Is it possible to realize this by the category for UITableViewCell
?
推荐答案
你不能直接到UITableViewCell,但是你可以为它的 contentView
:
You can't do this direct to UITableViewCell, but you can do it for its contentView
:
[[UIView appearanceWhenContainedIn:[UITableViewCell class], nil] setBackgroundColor:[UIColor redColor]];
请注意,它会更改所有子视图bg颜色。
Note that it will change all the subViews bg color.
另一种选择是用 UI_APPEARANCE_SELECTOR
标记写一个类别或子类 UITableViewCell
,检查这个问题:
Another option is writing a category or subclass the UITableViewCell
with UI_APPEARANCE_SELECTOR
mark, check this question:
iOS:使用UIAppearance定义自定义UITableViewCell颜色
这篇关于使用UIAppearance更改选定的单元格背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!