IOS layout: set the background color for the cell prototype

I ran into a very strange problem with Xcode 4.5.

I tried to set the background color for the prototype cell in my storyboard, but in the interface designer the cell color does not change, even when I run it on my device, it does not use the color that I set.

I tried to subclass UITableViewCell and set the background color in all init methods, but it still doesn't work.

PS: Xcode 4.5.1 and iOS 5 or 6, same thing. Since I'm a new developer, I can't remember if he worked on previous versions of Xcode.

+8
prototype uitableview interface-builder
source share
3 answers

I managed to add the background color to the UITableViewCell prototype inside the storyboard in Xcode 5.

First, select the cell that you want to assign to the background color.

Next, goto View โ†’ Utilities โ†’ Identity Inspector and add a new user-defined Runtime attribute for the backgroundColor key path of the Color and Value type of any color you want.

Screenshot of Identity Inspector panel

+6
source share

@dvkch: I donโ€™t know how you did it by deleting and re-creating segues. The only way I know to set the background color of a table cell is to set the background color of the presentation of the contents of the cell:

 cell.contentView.backgroundColor = [UIColor orangeColor]; 

Unfortunately, the storyboard does not display content properties.


EDIT

If you change the background color in the form of a table, the background color of the cell will also change.

+4
source share

Finally, it worked after some operations with the Clean and Clean folder, some removal of segues and after their recreation ... Thanks Xcode 4.5!

EDIT: after several tests: on iOS6 and 7, you really should be able to set the correct background color in the storyboards or your code by setting the background color in the cell prototype itself and in the contentView. These are not the same objects in the storyboard. Hope this helps.

-one
source share

All Articles