问题描述
我正在以编程方式将 UISegmentedControl 添加到导航栏 titleView 应该在的位置.但正如 Apple docs 所提到的在 titleView 下,如果 leftBarButtonItem 不为 nil,则忽略此属性.
I'm adding a UISegmentedControl to the Navigation bar programatically where the titleView should be. But as Apple docs have mentioned under titleView, This property is ignored if leftBarButtonItem is not nil.
但我也想要返回按钮.就像他们在自己的图片中展示的一样!
But I want to have the back button as well. Like they have illustrated in their own images!
下面是我添加UISegmentedControl的代码.
self.navigationItem.leftBarButtonItem = nil;
UISegmentedControl *statFilter = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Filter_Personnal", @"Filter_Department", @"Filter_Company", nil];
[statFilter setSegmentedControlStyle:UISegmentedControlStyleBar];
self.navigationItem.titleView = statFilter;
还有其他方法可以添加 UISegmentedControl 以及返回按钮吗?
Is there another way to add a UISegmentedControl along with the Back button as well?
谢谢.
推荐答案
试试这个
去掉这一行---> self.navigationItem.leftBarButtonItem = nil;
改为添加这个
UISegmentedControl *statFilter = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Filter_Personnal", @"Filter_Department", @"Filter_Company", nil]];
[statFilter setSegmentedControlStyle:UISegmentedControlStyleBar];
[statFilter sizeToFit];
self.navigationItem.titleView = statFilter;
唯一的改变是我添加了这一行:
Only change is I have added this line :
[statFilter sizeToFit];
希望对你有帮助!!!
这篇关于导航栏中带有返回按钮的 UISegmentedControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)