UISegmentedControl in the Navigation Bar with the Back button(导航栏中带有返回按钮的 UISegmentedControl)
问题描述
我正在以编程方式将 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:导航栏中带有返回按钮的 UISegmentedControl
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
