TabbarController的封装

来源:互联网 发布:红米手机壳淘宝 编辑:程序博客网 时间:2024/06/05 20:27

首先建立一个类继承自UITabBarController
.m中实现代码:

    - (void)viewDidLoad {    [super viewDidLoad];    ViewController *firstVc = [[ViewController alloc] init];    [self addChildVc:firstVc title:@"你好" image:@"mengmeng" selectedImage:@""];    SecondViewController *secondVc = [[SecondViewController alloc] init];    [self addChildVc:secondVc title:@"hello" image:@"jiyi" selectedImage:@""];}- (void)addChildVc:(UIViewController *)childVC title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{    childVC.title = title;//同时设置tabBar和navgationBar的文字    //设置控制器的图片    childVC.tabBarItem.image = [UIImage imageNamed:image];    childVC.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];    //设置导航控制器    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:childVC];    //添加为子控制器    [self addChildViewController:nav];}

在AppDelegate中

self.window.rootViewController = [[QZTabBarController alloc] init];

就可以了

原创粉丝点击