开发者

How to subClass UITableViewCell and use it to not clear UILabel background color on UITabeViewCell selected?

开发者 https://www.devze.com 2023-01-08 21:32 出处:网络
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 viewDidLoa

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 UITable开发者_JAVA百科ViewController 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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消