滚动控制器

/自己创建类
#import “SlideSwitchExample1.h”
#import “TouTiaoViewController.h”
#import “ShipinViewController.h”
#import “BeijingViewController.h”
#import “CepingViewController.h”
#import “DaogouViewController.h”
#import “XincheViewController.h”
#import “WancheViewController.h”
#import “ShuocheViewController.h”
#import “WenzhangViewController.h”

//第三方导入
#import “CKSlideMenu.h”

@interface SlideSwitchExample1 ()

@end

@implementation SlideSwitchExample1

(void)viewDidLoad {
[super viewDidLoad];
[self buildUI];
}

(void)buildUI {
self.view.backgroundColor = [UIColor whiteColor];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(370,20, 40,40)];
[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btn) forControlEvents:UIControlEventTouchUpInside];
btn.backgroundColor = [UIColor orangeColor];
[btn setTitle:@“➕” forState:UIControlStateNormal];

//要显示的标题
NSArray *titles = @[@“头条”,@“视频”,@“北京”,@“测评”,@“导购”,@“新车”,@“玩车”,@“说车”,@“文章”];
//创建需要展示的ViewController
NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
for (NSInteger i = 0 ; i<titles.count; i++) {
UIViewController *vc = [self viewControllerOfIndex:i];
[viewControllers addObject:vc];
}
CKSlideMenu *slideMenu = [[CKSlideMenu alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width-60, 40) titles:titles controllers:viewControllers];
slideMenu.bodyFrame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height);
slideMenu.bodySuperView = self.view;
slideMenu.indicatorStyle = SlideMenuIndicatorStyleFollowText;
slideMenu.indicatorOffsety = 0;
slideMenu.titleStyle = SlideMenuTitleStyleAll;
slideMenu.indicatorHeight = 2;
slideMenu.showIndicator = NO;
[self.view addSubview:slideMenu];
[self.view addSubview:btn];
}

(UIButton *)moreButton {
UIButton *button = [[UIButton alloc] init];
[button setTitle:@“➕” forState:UIControlStateNormal];
[button addTarget:self action:@selector(btn) forControlEvents:UIControlEventTouchUpInside];
// [button setImageEdgeInsets:UIEdgeInsetsMake(8, 8, 8, 8)];
return button;
}

(UIViewController *)viewControllerOfIndex:(NSInteger)index {
UIViewController *vc;
switch (index%2) {
case 0:
vc = [[TouTiaoViewController alloc] init];
break;
case 1:
vc = [[ShipinViewController alloc] init];
break;
case 2:
vc = [[BeijingViewController alloc] init];
break;
case 3:
vc = [[CepingViewController alloc] init];
break;
case 4:
vc = [[DaogouViewController alloc] init];
break;
case 5:
vc = [[XincheViewController alloc] init];
break;
case 6:
vc = [[WancheViewController alloc] init];
break;
case 7:
vc = [[ShuocheViewController alloc] init];
break;
case 8:
vc = [[WenzhangViewController alloc] init];
break;
default:
break;
}
return vc;
}

(void)btn{
NSLog(@“1221”);
}
//隐藏系统导航栏

(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];//调用父类方法
self.navigationController.navigationBarHidden = YES;
//更改状态栏样式
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];//调用父类方法
self.navigationController.navigationBarHidden = NO;
}

猜你喜欢

转载自blog.csdn.net/chuck_phonics/article/details/84889773