iOS 8: setting background color UITableView via UIAppearance

梦想与她 提交于 2019-12-14 04:25:28

问题


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


来源:https://stackoverflow.com/questions/25924926/ios-8-setting-background-color-uitableview-via-uiappearance

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