Pages

Wednesday, May 4, 2011

[Code Snippet] UITableViewCell background color

Let's go with the code snippet for this week. Recently I had to load some data in a UITableView controller and mark some cells with a different background color depending of its priority, so I tried to set the background color programatically in the cellForRowAtIndexPath method but nothing happends.

So looking for the internet I found this little code snippet that allows us to change UITableViewCell background color programatically.

UIView *bg = [[UIView alloc] initWithFrame:cell.frame];
bg.backgroundColor = [UIColor greenColor]; // or any color
cell.backgroundView = bg;
[bg release];

Enjoy it!

No comments:

Post a Comment