我正在以编程方式将 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!