如何在iPhone应用程序中的UINavigationBar中添加图像 [英] How to add image in UINavigationBar in IPhone app

查看:130
本文介绍了如何在iPhone应用程序中的UINavigationBar中添加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我想在导航栏中添加图片(徽标)。我正在使用XCode 4.2和iOS 5.

In my app, i want to add image(logo) in Navigation bar. I am working on XCode 4.2 and iOS 5.

我知道 UINavigationBar UIToolBar 在iOS 5中已更改。因此iOS 4.2 UINavigationBar 代码在iOS 5中无效。

I know UINavigationBar, UIToolBar has been changed in iOS 5. So iOS 4.2 UINavigationBar code won't work in iOS 5.

我想在4.2和5版本中支持 UINavigationBar 中的显示图像。

I want to support display image in UINavigationBar in both 4.2 and 5 version.

我想要在 UINavigationBar 中显示图像,如下面的屏幕截图所示。

I want to be display image in UINavigationBar like as in below screenshot.

请帮忙解决这个问题,如果有任何示例代码意味着它对我。

Please help in this regards and if there is any sample code means its very helpful to me.

谢谢!!!

推荐答案

一种方法这是使用 UINavigationItem.titleView UINavigationItem.rightBarButtonItem 。像这样:

One way to do this is to use UINavigationItem.titleView and UINavigationItem.rightBarButtonItem. Like this :

viewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourimage.png"]];
UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourimage2.jpg"]]];    
viewController.navigationItem.rightBarButtonItem = item;    

这里我使用 UIImageView 作为自定义视图,但它可以是带有自定义图像的 UIButton

Here I am using UIImageView as custom view, but it can be UIButton with custom image.

这篇关于如何在iPhone应用程序中的UINavigationBar中添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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