我最近从Swift 2迁移到了Swift 3,而且我被困在一个部分。在我的AppDelegate中,我将设置UINavigationBar的默认设置,如下所示。我遇到的挑战是在Swift 3中不再识别setBackgroundImage,我找不到替代方案。
有没有人遇到同样的问题并且能够解决它?
let turquoiseBackgroundImage:UIImage = UIImage(named: "navigationBarTurqoise")!
**// TODO Below is not working with Swift 3
UINavigationBar.appearance().setBackgroundImage(turquoiseBackgroundImage, forBarPosition: .Default)**
// Set up Back button to be white in Navigation bar
UINavigationBar.appearance().barStyle = UIBarStyle.default
UINavigationBar.appearance().tintColor = UIColor.white
// Font Name and Size of Title in Navigation Bar
if let font = UIFont(name: "TitilliumWeb-Light", size: 20) {
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName : font, NSForegroundColorAttributeName : UIColor.white]
}
// Remove hairline between navigation bar and anything below such as search bar
UINavigationBar.appearance().shadowImage = UIImage()
// Set up status bar (battery, time, etc.) to white
UIApplication.shared.statusBarStyle = .lightContent
答案 0 :(得分:6)
UINavigationBar.appearance().setBackgroundImage(turquoiseBackgroundImage, forBarPosition: .Default)
像这样重写代码
UINavigationBar.appearance().setBackgroundImage(turquoiseBackgroundImage, for: .default)