带有Swift的AppDelegate中的UINavigationBar setBackgroundImage [英] UINavigationBar setBackgroundImage in AppDelegate with Swift

查看:142
本文介绍了带有Swift的AppDelegate中的UINavigationBar setBackgroundImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Swift的App Delegate中将背景图像全局设置为导航栏. 我可以像这样在单个View Controller上运行它:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆