sujay
sujay

Reputation: 1845

Setting segmented control at the centre of the tab

I am working with the segmented control. I am using the following code to set it at the left of the tab.

 segmentedControl = [[UISegmentedControl alloc] initWithItems:nil];
 segmentedControl.segmentedControlStyle =
 UISegmentedControlStyleBezeled;
 segmentedControl.frame = CGRectMake(100,10,220,35);
 [segmentedControl insertSegmentWithTitle:@"Male" atIndex:0
 animated:YES];
 [segmentedControl insertSegmentWithTitle:@"Female" atIndex:1
 animated:YES];
 segmentedControl.selectedSegmentIndex = 1;
 [segmentedControl setMomentary:NO];
 [segmentedControl addTarget:self action:@selector(segmentSwitch:)
 forControlEvents:UIControlEventValueChanged];

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

My question is how can we set it at the center of the tab bar, as it is not taking the CGRect() values to set the position.

Upvotes: 0

Views: 760

Answers (1)

EmptyStack
EmptyStack

Reputation: 51374

I think you are trying to add the UISegmentedControl to UINavigationBar not UITabBar. If you want it at the center you can set it as the titleView of navigationItem.

self.navigationItem.titleView = segmentedControl;

Upvotes: 2

Related Questions