1.导入第三方XHSegmentController
2.创建继承SegmentSampleViewController的文件
3.在App.m中
#import "AppDelegate.h"
#import "SegmentSampleViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
SegmentSampleViewController *vc = [[SegmentSampleViewController alloc] init];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
return YES;
}
4.v.m中写控制器背景颜色
[self.view setBackgroundColor:[UIColor whiteColor]];
5.创建3个继承ViewController
6.在SegmentSampleViewController.h中
#import <UIKit/UIKit.h>
#import "XHSegmentViewController.h"
@interface SegmentSampleViewController : XHSegmentViewController
@end
.m中
#import "SegmentSampleViewController.h"
#import "ViewController.h"
#import "oneViewController.h"
#import "twoViewController.h"
@interface SegmentSampleViewController ()
@end
@implementation SegmentSampleViewController
- (void)viewDidLoad {
[super viewDidLoad];
ViewController *vc1 = [[ViewController alloc] init];
vc1.title = @"男装";
oneViewController *vc2 = [[oneViewController alloc] init];
vc2.title = @"女装";
twoViewController *vc3 = [[twoViewController alloc] init];
vc3.title = @"童装";
self.viewControllers = @[vc1, vc2, vc3];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end