Cannot get the Segmented control on the left side of a navigation bar
I am trying to add a UISegementedCo开发者_JAVA百科ntrol to the left side of a nav bar programmatically. I can get it to show in the middle by setting the control to the titleView as shown below. The following is the code that I have
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;
Any help is appreciated.
Have you tried
[[UIBarButtonItem alloc] initWithCustomView:...]
?
To be more precise, maybe something like
UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
self.navigationItem.leftBarButtonItem = item;
[item release];
精彩评论