I am new in iPhone app development. I am using customized uisegmentedcontrol inside navigation bar.
This code works well for iPhone.
[self.navigationItem setHidesBackButton:YES animated:YES];
profileSegmentControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects: @"seg1", @"seg2", @"seg3", @"seg4", nil]];
[profileSegmentControl addTarget:self action:@selector(seg1Button) forControlEvents:UIControlEventValueChanged];
**profileSegmentControl.frame = CGRectMake(40, 25, 310, 30);**
profileSegmentControl.segmentedControlStyle = UISegmentedControlStyleBar;
profileSegmentControl.momentary = YES;
//[profileSegmentControl sizeToFit];
UIBarButtonItem *profileSegmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:profileSegmentControl];
self.navigationItem.rightBarButtonItem = profileSegmentBarItem;
Now, when I change the orientation from portrait to landscape, how to change the uisegmentedcontroll buttons' co-ordinates in CGRectMake? When in landscape, the width should be 510 instead of 310.
Cannot use [segmentControlObject sizeToFit] as i have hidden the "back" navigation button of navigation bar. I tried this, but the width of segmentedControl does not cover the entire navigation bar.
I am aware of (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation method, but you cannot call this under viewDidLoad or under any method.
Using xcode 4.6