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
?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
You can't do this direct to UITableViewCell, but you can do it for its
contentView
:Note that it will change all the subViews bg color.
Another option is writing a category or subclass the
UITableViewCell
withUI_APPEARANCE_SELECTOR
mark, check this question:iOS: Using UIAppearance to define custom UITableViewCell color
Using appearance proxy you can colour all cells. Don't know if you can target specific category.
To do the colouring put following code in your AppDelegate.m file:
Put
[self customCellBackground];
in- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions
and somewhere at the end:
As null's answer is not for selected cell backgrounds and Armands L.'s answer did not work consistently for me (selecting cells by 'user-tap' did work, but programmatical cell selection showed strange results (like sometimes the selected background was not visible, or did not fill the cell's height properly...).
I found a custom solution that worked:
UITableViewCell
self.selectedBackgroundView
ininit
andUIColor
property withUI_APPEARANCE_SELECTOR
for custom selected background color.h
file:.m
file:in
init
method(s):self.selectedBackgroundView = [[UIView alloc] init];
and last but not least the setter function for the color: