在iOS 7中设置导航栏图像 [英] Set navigation bar image in iOS 7

查看:113
本文介绍了在iOS 7中设置导航栏图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我当前的项目从iOS 6转换为iOS 7.
在iOS 6中我的项目工作正常,但在iOS 7中导航栏图像显示不正确。

I want to convert my current project from iOS 6 to iOS 7. In iOS 6 my project is working fine, but in iOS 7 navigation bar image is not showing properly.

我在iOS 6上使用了这段代码片段,

I used this code snippet for iOS 6,

UIImage *imgNav = [UIImage imageNamed:@"navigation.png"];
self.navigationController.navigationBar.frame = CGRectMake(0, 0, 320, 44);
[self.navigationController.navigationBar setBackgroundImage:imgNav forBarMetrics:
     UIBarMetricsDefault];

如何在iOS 7中设置导航栏图像?

How can I set the navigation bar image in iOS 7?

推荐答案

尝试在AppDelegate中添加以下代码

Try Adding the below code in AppDelegate

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigation.png"] 
                                   forBarMetrics:UIBarMetricsDefault];

这是Swift版本:

UINavigationBar.appearance().setBackgroundImage(UIImage.init(named: "navigation.png"), forBarMetrics: UIBarMetrics.Default)

Swift 3版本:

Swift 3 version :

UINavigationBar.appearance().setBackgroundImage(UIImage.init(named: "logo-dark.png"), for: UIBarMetrics.default)

这篇关于在iOS 7中设置导航栏图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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