由于难度不大,直接上代码了,看一遍基本就明白思路了


1.创建一个tabBarViewController

.m文件

#import "SSTabBarViewController.h"
#import "constant.h"

@interface SSTabBarViewController ()

@end

@implementation SSTabBarViewController


-(instancetype)init
{
    self = [super init];
    if (self) {
        UINavigationController * newNavigationController = [WPUtil getViewControllerWithIdentifier:@"new" storyboardName:@"New"];
        
        UINavigationController * alreadyNavigationController = [WPUtil getViewControllerWithIdentifier:@"already" storyboardName:@"Already"];
        
        UINavigationController * myNavigationController = [WPUtil getViewControllerWithIdentifier:@"my" storyboardName:@"My"];
        
        UINavigationController * moreNavigationController = [WPUtil getViewControllerWithIdentifier:@"more" storyboardName:@"More"];
        
        self.viewControllers = @[newNavigationController, alreadyNavigationController, myNavigationController, moreNavigationController];
        
        UITabBarItem * newItem = self.tabBar.items[0];
        newItem.title = @"新订单";
        newItem.image = [[UIImage imageNamed:@"xindingdan_hui"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        newItem.selectedImage = [[UIImage imageNamed:@"xindingdan_lv"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        UITabBarItem * alreadyItem = self.tabBar.items[1];
        alreadyItem.title = @"已处理";
        alreadyItem.image = [[UIImage imageNamed:@"yichuli_hui"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        alreadyItem.selectedImage = [[UIImage imageNamed:@"yichuli_lv"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        UITabBarItem * myItem = self.tabBar.items[2];
        myItem.title = @"我的";
        myItem.image = [[UIImage imageNamed:@"wode_hui"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        myItem.selectedImage = [[UIImage imageNamed:@"wode_lv"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        UITabBarItem * moreItem = self.tabBar.items[3];
        moreItem.title = @"更多";
        moreItem.image = [[UIImage imageNamed:@"gengduo_hui"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        moreItem.selectedImage = [[UIImage imageNamed:@"gengduo_lv"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    
    
    return self;
}

-(void)viewDidLoad {
    [super viewDidLoad];
}


@end

2.在appDelegate中设置,将window的rootView设置为我们的tabBar

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    SSTabBarViewController * tabBar = [[SSTabBarViewController alloc] init];
    self.window.rootViewController = tabBar;
    [self.window makeKeyAndVisible];
    
    
    return YES;
}

注:这里一定要记得初始化window,否则会造成黑屏

3.设置程序启动后默认进入的viewController
图片描述

4.注意:如果设置了navigationController此时该viewController的storyboard ID要设置在navigationController上
图片描述

5.顺便说一句,当隐藏tabBar的时候,如果controllerView上有tableView,那么此时你需要用下面这段代码来让tableView顶部不留下空白部分:

self.automaticallyAdjustsScrollViewInsets = NO;

ShevaKuilin
388 声望32 粉丝

世间好物不坚牢,彩云易碎琉璃脆。