curso programacion iphone

Changing the background color of the selected cell in a UITableView

The default value for selectedBackgroundView is nil for cells in plain-style tables (UITableViewStylePlain) and non-nil for section-group tables (UITableViewStyleGrouped).

If you’re using a plain-style table, you must alloc an init a new UIView with the desired background color, and then assign it to selectedBackgroundView.

Otherwise, if you just want a gray background, you should use:

Tagged with:  

2 Responses to How to change the highlighted background color of a UITableView’s cell

  1. ing says:

    You are right, BUT there real matter is for CUSTOM cell view…

  2. Jason Pinta says:

    i know is old, but i found the solution for custom cells.

    in your customcell class add the:

    – (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    }

    and the:

    - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    [super setHighlighted:highlighted animated:animated];
    }

    And you can do pretty much anything with the cells child objects with this, for example an image or a label or just add a view on the background and change its color with this.

    Cheers

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>