我正在尝试以编程方式将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;
感谢任何帮助。
答案 0 :(得分:3)
你试过吗
[[UIBarButtonItem alloc] initWithCustomView:...]
更确切地说,可能是
之类的东西UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
self.navigationItem.leftBarButtonItem = item;
[item release];