使用 Swift 在 AppDelegate 中设置 UINavigationBar setBackgroundImage [英] UINavigationBar setBackgroundImage in AppDelegate with Swift
本文介绍了使用 Swift 在 AppDelegate 中设置 UINavigationBar setBackgroundImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Swift 的 App Delegate 中全局设置导航栏的背景图像.我可以让它在这样的单个视图控制器上工作:
I am trying to set a background image to the navigation bar globally in the App Delegate in Swift. I can get it to work on an individual View Controller like this:
var topBar: UINavigationBar!
topBar.setBackgroundImage(UIImage(named: "navbar"), forBarMetrics:
.Default)
但是当我尝试将以下内容添加到 App Delegate 时,它会因未捕获的异常而崩溃:
But when I try and add the following to the App Delegate, it crashes with an uncaught exception:
UINavigationBar.appearance().setBackgroundImage(UIImage(named:
"navbar"), forBarMetrics: .Default)
推荐答案
好的,我删除了导航栏并在情节提要中添加了新的导航栏……现在它只适用于 App Delegate 代码.我猜这只是 Xcode 6/Swift 出了问题.
OK, I deleted the navigation bars and added new ones in the storyboard... now it works with just the App Delegate code. It's just Xcode 6/Swift being buggy, I guess.
这篇关于使用 Swift 在 AppDelegate 中设置 UINavigationBar setBackgroundImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文