iOS 8: setting background color UITableView via UI

2019-07-07 01:37发布

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.

4条回答
别忘想泡老子
2楼-- · 2019-07-07 02:12

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

查看更多
走好不送
3楼-- · 2019-07-07 02:16

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楼-- · 2019-07-07 02:18

It works for me:

[[UITableView appearance] setBackgroundColor:[UIColor clearColor]];
[[UITableView appearance] setBackgroundColor:[UIColor blueColor]];
查看更多
smile是对你的礼貌
5楼-- · 2019-07-07 02:20

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
查看更多
登录 后发表回答