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

查看:19
本文介绍了在 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 版本:

This is the Swift Version:

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天全站免登陆