[英]UISegmentedControl in the Navigation Bar with the Back button
我正在以编程方式在导航栏中添加一个UISegmentedControl
,其中titleView
应该是。 但正如Apple文档在titleView
下提到的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
和Back按钮吗?
谢谢。
试试这个
删除这一行---> 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];
希望这可以帮助 !!!
您可以使用自定义视图创建UIBarButtonItem
,该视图可能是您的UISegmentedControl
。
以下内容可能有效。
//create segmented control with items
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"One", @"Two", nil]];
//create bar button item with segmented control as custom view
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
//add segmented control bar button item to navigation bar
[[[self navigationController] navigationItem] setRightBarButtonItem:barButtonItem];
我没有对此进行测试,但它应该沿着您需要的正确线路进行测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.