自定义tabBar类
在customTabBarCtrl.h中
#import <UIKit/UIKit.h>
@interface customTabBarCtrl : UITabBarController
@end
在customTabBarCtrl.m中
#import "customTabBarCtrl.h"
#import "mainViewController.h"
#import "loveViewController.h"
#import "mineViewController.h"
@implementation customTabBarCtrl
- (void)viewDidLoad {
[super viewDidLoad];
[self dismissViewControllerAnimated:NO completion: nil];
UINavigationController *nav;
UIViewController *mainVC = [[mainViewController alloc]init];
nav = [[UINavigationController alloc] initWithRootViewController: mainVC];
nav.tabBarItem.image = [UIImage imageNamed:@"首页-灰色.png"];
nav.tabBarItem.selectedImage = [UIImage imageNamed:@"首页-绿色.png"];
nav.tabBarItem.title = @"首页";
[self addChildViewController: nav];
UIViewController* loveVC = [[loveViewController alloc] init];
nav = [[UINavigationController alloc] initWithRootViewController: loveVC];
nav.tabBarItem.image = [UIImage imageNamed:@"爱心-灰色.png"];
nav.tabBarItem.selectedImage = [UIImage imageNamed:@"爱心-绿.png"];
nav.tabBarItem.title = @"爱心";
[self addChildViewController: nav];
UIViewController* VC3 = [[UIViewController alloc] init];
nav = [[UINavigationController alloc] initWithRootViewController: VC3];
nav.tabBarItem.image = [UIImage imageNamed:@"亲情-灰色.png"];
nav.tabBarItem.selectedImage = [UIImage imageNamed:@"亲情-绿色.png"];
nav.tabBarItem.title = @"亲情";
[self addChildViewController: nav];
UIViewController* mineVC = [[mineViewController alloc] init];
nav = [[UINavigationController alloc] initWithRootViewController: mineVC];
nav.tabBarItem.image = [UIImage imageNamed:@"我的-灰色.png"];
nav.tabBarItem.selectedImage = [UIImage imageNamed:@"我的-绿色.png"];
nav.tabBarItem.title = @"我的";
[self addChildViewController: nav];
}
-(void)viewWillAppear:(BOOL)animated {
self.navigationController.navigationBarHidden = YES;
}
在登录页面中,点击登录跳转的方法中执行下面代码
UITabBarController *tabBarCtrl = [[customTabBarCtrl alloc]init];
[self presentViewController:tabBarCtrl animated:NO completion:nil];