UITableView background color iOS 9

橙三吉。 提交于 2020-01-03 08:28:50

问题


I have a UITableView that I want to set its background color to transparent. Background color for the table view and all subviews at interface builder is set to transparent. It works fine for iOS 8 & 7. but, not iOS 9. any idea?

cellForRowAtIndexPath method:

[cell setSelectedBackgroundView:[[UIView alloc] init]];
[cell.selectedBackgroundView setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundColor:[UIColor clearColor]];
[cell.contentView setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundView:[[UIView alloc] init]];
[cell.backgroundView setBackgroundColor:[UIColor clearColor]];

回答1:


Objective-c:

[self.yourTableView setBackgroundColor:[UIColor clearColor]];

Swift:

self.yourTableView.backgroundColor = .clear

XCode 7.0 bug. Not picking up from Storyboard




回答2:


This happens to me even when creating an UITableView in code, and setting it as a private property of my UIViewController. However, if the UITableView is a global variable, this problem does not occur.

I suspect Apple is rooting around the ivars on my UIViewController, setting UITableView's background colors to UIColor whiteColor without asking me. I have checked, and the calls to do go through setBackgroundColor on the UITableView.



来源:https://stackoverflow.com/questions/31903910/uitableview-background-color-ios-9

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