我正在以编程方式将 UISegmentedControl
添加到导航栏,该位置应该是 titleView
。但是作为Apple docs在 titleView
下已经提到,如果 leftBarButtonItem 不为 nil,则忽略此属性。
但我也想要后退按钮。就像他们在自己的图片中说明的一样!
下面是我添加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
以及后退按钮吗?
谢谢。
最佳答案
试试这个
删除这一行---> 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;
唯一的变化是我添加了这一行:
[statFilter sizeToFit];
希望这对您有帮助!!!
关于ios - 带有后退按钮的导航栏中的 UISegmentedControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15383014/