iOS storyboard: set a background color to prototyp

2019-06-17 01:15发布

I am facing a very strange issue with XCode 4.5.

I tried to set a background color to a prototype cell in my storyboard, but in interface builder the cell color doesn't change, even when I run it on my device it doesn't use the color I set.

I tried creating a subclass of UITableViewCell and setting the color of the background in all init methods but it still donnot work.

PS: XCode 4.5.1 and iOS 5 or 6, same issue. Since I'm a new developer I cannot recall if it worked on previous versions of XCode.

3条回答
迷人小祖宗
2楼-- · 2019-06-17 01:35

It finally worked after some Clean and Clean build folder operations, some deletion of segues and after recreated them... Thanks Xcode 4.5 !

EDIT: after multiple tests: on iOS6 and 7 you actualy should be able to set the correct background color in storyboards or your code by setting the background color on the cell prototype itself and the contentView. Those are not the same objects in a storyboard. I hope that helps.

查看更多
别忘想泡老子
3楼-- · 2019-06-17 01:36

I was able to add a background color to a prototype UITableViewCell inside of a storyboard in Xcode 5.

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

Next, goto View -> Utilities -> Identity Inspector and add a new User Defined Runtime Attribute for a Keypath of "backgroundColor" a type of "Color" and a "Value" of whatever color you want.

Screenshot of Identity Inspector panel

查看更多
Explosion°爆炸
4楼-- · 2019-06-17 01:47

@dvkch: I don't know how you did it with deleting and recreating segues. The only way I know to set the background color of table view cell is to set the content views background color of the cell:

cell.contentView.backgroundColor = [UIColor orangeColor];

Sadly, storyboard doesn't show the content views properties.


EDIT

If you change the background color of the table view the background color of the cell changes, too.

查看更多
登录 后发表回答