iOS storyboard: set a background color to prototype cell

假装没事ソ 提交于 2019-12-08 16:31:58

问题


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.


回答1:


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.




回答2:


@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.




回答3:


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.



来源:https://stackoverflow.com/questions/12861289/ios-storyboard-set-a-background-color-to-prototype-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!