使用标题视图自定义导航栏 [英] Customize navigation bar with title view

查看:127
本文介绍了使用标题视图自定义导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在导航栏的中心添加自定义视图,并使用以下代码对其进行测试:

I am trying to add a custom view in the center of a navigation bar and I am using the following code to test it:

UIView * testView = [[UIView alloc] init];
[testView setBackgroundColor:[UIColor blackColor]];
testView.frame = CGRectMake(0, 0, 100, 35);
[self.navigationController.navigationItem.titleView addSubview:testView];

我在我的视图控制器的viewDidLoad方法中设置了这个,但是当我运行我的程序时
我的导航栏中似乎没有任何变化。

I am setting this up in the viewDidLoad method of my view controller but when i run my program nothing seems to change in my navigation bar.

你可以帮我这个吗?

推荐答案

这个有效。在初始化时给出框架

This works. Give frame at the time of initialisation

 UIView *iv = [[UIView alloc] initWithFrame:CGRectMake(0,0,32,32)];
 [iv setBackgroundColor:[UIColor whiteColor]];
  self.navigationItem.titleView = iv;

这篇关于使用标题视图自定义导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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