开发者

Background image for list view still shows white behind text for cells

I wanted to put a background image partially visible behind a list view. I created a list view in my nib with an image view behind it and made the list view background 20% opacity. This allows the background image to show thru but my text in the cells show a white background behind and if I create the cells in cellForRowAtIndexPath the cells have a white background too.

I am creating and setting the cell textLabel and the de开发者_如何学运维tailTextLabel in the cellForRowAtIndexPath event.

Not sure how to get rid of that, or if there is a better way to do the background image.


I had a similar issue and resolved it by setting the cell.contentView.backgroundColor to [UIColor clearColor] in cellForRowAtIndexPath.

If you did not want to make the whole cell transparent but the labels only, you can set the backgroundColor attribute of the textLabel and detailTextLabel to clear as well:

cell.textLabel.backgroundColor = [UIColor clearColor];

To set the background image of a table at run time rather than in a nib you can create a new UIColor from an image. Like so:

UIImage *img = [UIImage imageWithContentsOfFile: someFilePath];  // get your background image
UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage: img];
[myTable setBackgroundColor: backgroundColor]; 
[backgroundColor release];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜