我怎样才能获得一个完整大小的UINavigationBar titleView [英] How can I get a full-sized UINavigationBar titleView

查看:119
本文介绍了我怎样才能获得一个完整大小的UINavigationBar titleView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在UINavigationBar中添加自定义控件作为titleView。当我这样做时,尽管设置框架和通常假设全宽的属性,我得到这个:

I am trying to add a custom control as the titleView in a UINavigationBar. When I do so, despite setting the frame and the properties that would normally assume full width, I get this:

可以忽略亮蓝色,因为它是我隐藏自定义控件的地方。问题是酒吧两端的窄条导航栏。我如何摆脱这些因此我的自定义视图将延伸100%?

The bright blue can be ignored as it is where I am hiding my custom control. The issue is the narrow strips of navbar at the ends of the bar. How can I get rid of these so my customview will stretch 100%?

CGRect frame = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.width, kDefaultBarHeight);
UANavBarControlView *control = [[[UANavBarControlView alloc] initWithFrame:frame] autorelease];
control.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
self.navigationItem.titleView = control;

PS - 我知道我可以自己添加视图,而不是附加到导航栏,它我自己很容易定位它。我有理由要求它在导航栏上,这些原因是这里

PS - I know I can add the view by itself instead of being attached to a navigation bar and it would be very easy to position it myself. I have my reasons for needing it to be "on" the navigation bar, and those reasons are here

推荐答案

设置视图的titleView的navigationItem永远不会有效。相反,您可以将子视图添加到导航控制器的navigationBar:

Setting the titleView of your view's navigationItem will never do the trick. Instead, you can add a subView to the navigation controller's navigationBar :

UIView* ctrl = [[UIView alloc] initWithFrame:navController.navigationBar.bounds];
ctrl.backgroundColor = [UIColor yellowColor];
ctrl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[navController.navigationBar addSubview:ctrl];

这篇关于我怎样才能获得一个完整大小的UINavigationBar titleView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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