我正在尝试以编程方式将 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/