Depending on how demanding the content four views is, I would suggest to make one main view for the segmented control and set up four container views in the main view. The three of them should be hidden and then you can toggle between the four views (show/hide).
This is only a good solution if the views' codes are very "soft" or it'll be very slow to run 4-5 views at the same time. If it's four hardcore views I would prefer to use the standard navigation tab bar control instead..
//////// EXAMPLE ////////
The setup will be with one UIViewController for the background. On this view we will place one UISegmentedControl + four container views. The four container views should be placed on the top of each other. The three of the container views are hidden so you only see one.
BackgroundViewController.h:
#import <UIKit/UIKit.h>
@interface BackgroundViewController : UIViewController {
IBOutlet UISegmentedControl *segmentedControl;
UIView actualView;
}
@property (nonatomic, weak) IBOutlet UIView *containerOne;
@property (nonatomic, weak) IBOutlet UIView *containerTwo;
@property (nonatomic, weak) IBOutlet UIView *containerThree;
@property (nonatomic, weak) IBOutlet UIView *containerFour;
@end
Here's an example of the IBAction for the segmented control.
- (void) viewDidLoad {
actualView = self.containerOne;
UIView *fromView = nil;
UIView *toView = nil;
self.containerOne.hidden = NO;
self.containerTwo.hidden = YES;
self.containerThree.hidden = YES;
self.containerFour.hidden = YES;
}
- (IBAction)segmentSwitchClick {
NSInteger selectedSegment = segmentedControl.selectedSegmentIndex;
UIView *fromView = actualView;
UIView *toView = nil;
switch (selectedSegment) {
case 0: {
toView = [self containerOne];
break;
}
case 1: {
toView = [self containerTwo];
break;
}
case 2: {
toView = [self containerThree];
break;
}
case 3: {
toView = [self containerFour];
break;
}
default:
break;
}
}
[UIView transitionFromView:fromView toView:toView duration:1.9 options:UIViewAnimationOptionShowHideTransitionViews | UIViewAnimationOptionCurveLinear
completion:^(BOOL finished) {
if (finished) {
actualView = toView;
}
}];
}
PS I haven't tried it, but it should work.