导航栏中带有返回按钮的 UISegmentedControl

UISegmentedControl in the Navigation Bar with the Back button(导航栏中带有返回按钮的 UISegmentedControl)
本文介绍了导航栏中带有返回按钮的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)