【发布时间】:2016-02-11 05:44:07
【问题描述】:
我在 SO 上找到了一堆链接,这些链接显示了如何在 Objective-C 中将导航栏设置为图像,但在 swift 中没有。我确实找到了,但没有帮助:UINavigationBar setBackgroundImage in AppDelegate with Swift
在didFinishLaunchingWithOptions 中AppDelegate 中,我正在尝试快速执行此操作但无济于事:
let headerImage = UIImage(named: "header.png")
UINavigationBar.appearance().setBackgroundImage(headerImage, forBarMetrics:.Default)
UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.Default
var navigationVC:UINavigationController = UINavigationController(rootViewController: tableVC)
let frame = UIScreen.mainScreen().bounds
window = UIWindow(frame: frame)
window!.rootViewController = navigationVC
window!.makeKeyAndVisible()
如何快速将导航栏设置为图片?
提前致谢。
【问题讨论】:
-
你的代码很好。问题在于图像本身。您确定将其添加到目标中吗?调试
headerImage并确保它不是nil -
如何确保已将其添加到目标中? postimg.org/image/pw1x4olrj 大概通过这张图片
header.png是在正确的位置......当在headerImage上设置断点时,应用程序下面的行崩溃给我一个 llDB 错误。 @乔恩 -
选择您的图像并打开实用程序视图。确保在 Target Membership 下有一个复选标记。这是截图:postimg.org/image/x0027l3nh
-
同样的事情...postimg.org/image/6tkqp1wm5
-
你尝试过其他图片吗?
标签: swift uinavigationbar swift2 appdelegate