In my app, I use a label to display a specified color by set background color in a customized UITableViewCell
(because this color maybe changed according incoming data from internet), after viewDidLoad, everything is ok, but when this cell is selected (highlighted) the color is cleared.
After searching, I found out that some someone have to subclass UITableViewCell
and overwrite setHighlight
method to not clear label background color. I have tried but unlucky.
So Does anybody know how to do this? the right way to subclass UITableViewCell
, then use it in UITableViewController
to not clear label background color? Please help me.
Thanks for any advice.
From the latest UITableViewCell
documentation:
Note: If you want to change the background color of a cell (by setting the background color of a cell via the backgroundColor property declared by UIView) you must do it in the tableView:willDisplayCell:forRowAtIndexPath: method of the delegate and not in tableView:cellForRowAtIndexPath: of the data source. Changes to the background colors of cells in a group-style table view has an effect in iOS 3.0 that is different than previous versions of the operating system. It now affects the area inside the rounded rectangle instead of the area outside of it.
Also, review the Table View Programming Guide for iOS for some of the best documentation.
override - (void)layoutSubviews of cell and set label.backgroundColor in there. that's work for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With