通过创建按钮来管理不同的控制器
通过button来创建菜单,并管理不同的控制器
/**
* 创建菜单按钮
*/
- (void)creatButtons{
NSArray *buttonTitleArr = @[@"首页",@"报告",@"设置",@"官网",@"帮助"];
for (int i = 0; i<5; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(50, 150+ (40 + 30)*i, 100, 40);
[button setTitle:buttonTitleArr[i] forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
[button setTitleColor:JLColor(18, 126, 84) forState:UIControlStateSelected];
[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
button.tag = 100 + i;
[self.buttonArray addObject:button];
if (i == 0) {
button.selected = YES;
}
[self.view addSubview:button];
}
}
/**
* 菜单按钮点击事件
*/
- (void)buttonClick:(UIButton *)button{
if (button.selected) {
[[self sideMenuController] closeMenu];
return;
}
for (UIButton *btn in self.buttonArray) {
if (btn.tag == button.tag) {
btn.selected = YES;
}else{
btn.selected = NO;
}
}
NSArray *VCarray = @[@"HomeViewController",@"reportViewController",@"settingViewController",@"homeSiteView",@"helpViewController"];
Class fatherVC = NSClassFromString(VCarray[button.tag - 100]);
UIViewController *controller = [[fatherVC alloc]init];
JLContentNavigationController *navC = [[JLContentNavigationController alloc]initWithRootViewController:controller];
[[self sideMenuController] changeContentViewController:navC closeMenu:YES];
}
*/
- (void)creatButtons{
NSArray *buttonTitleArr = @[@"首页",@"报告",@"设置",@"官网",@"帮助"];
for (int i = 0; i<5; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(50, 150+ (40 + 30)*i, 100, 40);
[button setTitle:buttonTitleArr[i] forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
[button setTitleColor:JLColor(18, 126, 84) forState:UIControlStateSelected];
[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
button.tag = 100 + i;
[self.buttonArray addObject:button];
if (i == 0) {
button.selected = YES;
}
[self.view addSubview:button];
}
}
/**
* 菜单按钮点击事件
*/
- (void)buttonClick:(UIButton *)button{
if (button.selected) {
[[self sideMenuController] closeMenu];
return;
}
for (UIButton *btn in self.buttonArray) {
if (btn.tag == button.tag) {
btn.selected = YES;
}else{
btn.selected = NO;
}
}
NSArray *VCarray = @[@"HomeViewController",@"reportViewController",@"settingViewController",@"homeSiteView",@"helpViewController"];
Class fatherVC = NSClassFromString(VCarray[button.tag - 100]);
UIViewController *controller = [[fatherVC alloc]init];
JLContentNavigationController *navC = [[JLContentNavigationController alloc]initWithRootViewController:controller];
[[self sideMenuController] changeContentViewController:navC closeMenu:YES];
}
这些控制器都是自定义的控制器