iOS 8: setting background color UITableView via UI

2019-07-07 01:43发布

问题:

i am used to doing the following to style all instances of UITableView:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[UITableView appearance] setBackgroundColor:[UIColor blueColor]];
    return YES;
}

but on ios 8 this is not working anymore.

for the purpose of testing and demo i created a new master-detail project using xcode 6.0.1 which you can find on github.
running it on ios 7 works (table view gets blue background). on ios 8 not so much.

did i miss someting during the hype? is this a bug?

Update 2014-09-25

this appears to be a known bug. the apple radar # is 17974434 which is currently marked as open.

回答1:

Had the same problem, reported another bug to Apple (rdar://18537175): http://openradar.appspot.com/18537175



回答2:

It works for me:

[[UITableView appearance] setBackgroundColor:[UIColor clearColor]];
[[UITableView appearance] setBackgroundColor:[UIColor blueColor]];


回答3:

Swift 3.1 is working like this:

    UITableView.appearance().backgroundColor = UIColor.darkGray
    UITableView.appearance().tintColor =  UIColor.white
    UITableViewCell.appearance().backgroundColor = UIColor.darkGray
    UITableViewCell.appearance().tintColor = UIColor.white


回答4:

Swift 3.1 is working like this:

UITableView.appearance().backgroundColor = UIColor.darkGray
UITableView.appearance().tintColor =  UIColor.white
UITableViewCell.appearance().backgroundColor = UIColor.darkGray
UITableViewCell.appearance().tintColor = UIColor.white