如何在Objective-C的navigationBar中心添加图像? [英] How to add a image at the center of navigationBar in Objective-C?

查看:137
本文介绍了如何在Objective-C的navigationBar中心添加图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在IOS中开发,我使用以下代码设置 navigationBar 的背景。

I am developing in IOS , I use the following code to set a background to the navigationBar.

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bar-back"] forBarMetrics:UIBarMetricsDefault];

我想在 navigationBar 和$ code> navigationBar 的中心如下图所示。

And I want to add a image on navigationBar and center of navigationBar like the following picture.

如何在Objective-C中的navigationBar中心添加图像?

提前致谢。

推荐答案

设置导航标题视图如下所示

Set navigation title view like below

self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img.png"]];





编辑:

如果你有大图像然后使用下面的代码




if you have big image then use below code

UIImage *img = [UIImage imageNamed:@"1.png"];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[imgView setImage:img];
// setContent mode aspect fit
[imgView setContentMode:UIViewContentModeScaleAspectFit];
self.navigationItem.titleView = imgView;

这篇关于如何在Objective-C的navigationBar中心添加图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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