UINavigationBar setBackgroundImage in AppDelegate with Swift

无人久伴 提交于 2020-01-03 19:37:52

问题


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)

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)

回答1:


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.



来源:https://stackoverflow.com/questions/26723989/uinavigationbar-setbackgroundimage-in-appdelegate-with-swift

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