objective-c - 无法获取导航栏左侧的分段控件

标签 objective-c uisegmentedcontrol

我正在尝试以编程方式将 UISegementedControl 添加到导航栏的左侧。我可以通过将控件设置为 titleView 来使其显示在中间,如下所示。以下是我的代码

NSArray *buttonNames = [NSArray arrayWithObjects:@"One", @"Two", nil];
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc]
segmentedControl.segmentedControlStyle =  UISegmentedControlStyleBar;

// instead of the following I would like to move to left side of the nav bar
self.navigationItem.titleView = segmentedControl;

感谢任何帮助。

最佳答案

你试过吗

[[UIBarButtonItem alloc] initWithCustomView:...]


更准确地说,也许是这样的

UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
self.navigationItem.leftBarButtonItem = item;
[item release];

关于objective-c - 无法获取导航栏左侧的分段控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5301051/

相关文章:

ios - Realm : How to delete object from RLMArray?

iphone - 在 iPhone 上提取 UISegmentedControl 的图像

objective-c - 为分段控件中的选定分段自定义颜色

ios - 根据另一个 UISegmentedControl 的情况禁用 UISegmentedControl

objective-c - 横向 xib 仅适用于 ipad 版本

ios - 后台的通话中 voip 状态栏

ios - Spritekit bodyWithbodies 不起作用

ios - 使用 UISegmentedControl 发送的无法识别的选择器

ios - 对于 alertController : what is the sourceView of a selected segment in a UISegmentedControl

iOS AFNetworking post 请求返回 Request failed : bad request (400)