从一个登陆页跳转到一个具有多个导航页面的工具栏控制器UITabbarController中
方法如下:
(一)新建一个继承于UITabBarController控制器的控制器,在内部绑定多个以视图控制器进行初始化的导航控制器
(二)在登录的事件中创建一个新的上述的控制器对象 直接跳转即可
新建工具栏控制器如下:
编辑LayoutViewController.h如下:
//
// LayoutViewController.h
// 作业整理
//
// Created by apple on 15/9/15.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LayoutViewController : UITabBarController
@end
编辑 LayoutViewController.m如下:
//
// LayoutViewController.m
// 作业整理
//
// Created by apple on 15/9/15.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "LayoutViewController.h"
@interface LayoutViewController ()
@end
@implementation LayoutViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tabBar.barTintColor = [UIColor blueColor];
ViewController *vc1 = [[ViewController alloc] init];
[self TabVC:self setVC:vc1 withTabTitle:@"记录" withTabImgName:@"记录" withSecTabImgNam:@"记录1"];
ChatViewController *vc2 = [[ChatViewController alloc] init];
[self TabVC:self setVC:vc2 withTabTitle:@"交流" withTabImgName:@"交流" withSecTabImgNam:@"交流1"];
SquareViewController *vc3 = [[SquareViewController alloc] init];
[self TabVC:self setVC:vc3 withTabTitle:@"广场" withTabImgName:@"主题" withSecTabImgNam:@"主题1"];
MoreFormViewController *vc4 = [[MoreFormViewController alloc] init];
[self TabVC:self setVC:vc4 withTabTitle:@"更多" withTabImgName:@"我" withSecTabImgNam:@"我1"];
}
// 将属性设置封装在一个成员方法中
-(void)TabVC:(UITabBarController *)tab1 setVC:(UIViewController *) vc withTabTitle:(NSString *)tabtit withTabImgName:(NSString *) imgNam withSecTabImgNam: (NSString *) secImg
{
UINavigationController *navc= [[UINavigationController alloc] initWithRootViewController:vc];
navc.navigationBar.barTintColor = [UIColor blueColor];
navc.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName: [UIFont boldSystemFontOfSize:22]};
navc.tabBarItem.title = tabtit;
navc.tabBarItem.image = [UIImage imageNamed:imgNam];
navc.tabBarItem.selectedImage = [[UIImage imageNamed:secImg] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[navc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:15]} forState:UIControlStateNormal];
[navc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor blackColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:15]} forState:UIControlStateSelected];
[tab1 addChildViewController:navc];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
在登陆页调用如下:
layVC = [[LayoutViewController alloc] init];
[self.navigationController pushViewController:layVC animated:YES];
运行结果如下:
还没有评论,来说两句吧...