How to subClass a UITableViewCell and use it so as not to clear the UILabel color on the selected UITabeViewCell?

In my application, I use a shortcut to display the specified color by setting the background color in a custom one UITableViewCell(since this color can be changed according to incoming data from the Internet), after viewDidLoad everything is fine, but when this cell is (highlighted), the color is cleared.

After searching, I found out that someone should subclass UITableViewCelland overwrite the method setHighlightso as not to clear the background color of the label. I tried but no luck.

So does anyone know how to do this? the correct way to subclass UITableViewCelland then use it in UITableViewControllerorder not to clear the background color of the label? Please help me.

Thanks for any advice.

+3
source share
3 answers

From the latest documentation UITableViewCell:

Note. If you want to change the background color of the cell (by setting the background color of the cell through the backgroundColor property declared by UIView), you must do this in tableView: willDisplayCell: forRowAtIndexPath: delegate method and not in tableView: cellForRowAtIndexPath: data source. Changes in the background colors of cells in the group style table view have an effect in iOS 3.0, which differs from previous versions of the operating system. Now it affects the area inside the rounded rectangle, and not on the area outside it.

, iOS .

+3

override - (void) layoutSubviews label.backgroundColor.

+3

You will have to either override the view or use the UIImageView. See The UITableViewCell submenu disappears when a cell is selected for more information.

+1
source

Source: https://habr.com/ru/post/1756303/


All Articles