UITabBar

#import "MyMusicViewController.h"

#import "MusicRoomViewController.h"

#import "FindViewController.h"

#import "MoreViewController.h"


MyMusicViewController *myVC = [[MyMusicViewController alloc]init];


    // 包装导航控制器

    UINavigationController *myNav = [[UINavigationController alloc]initWithRootViewController:myVC];


    // 创建标签按钮

    UITabBarItem *item1 = [[UITabBarItem alloc]initWithTitle:@"我的音乐" image:[UIImage imageNamed:@"mymusic"] selectedImage:[UIImage imageNamed:@"mymusic_Highlighted"]];


    // 将按钮赋值给当前控制器的标签按钮

    myNav.tabBarItem = item1;



    // ======= 音乐馆 ========

    // 创建页面

    MusicRoomViewController *musicVC = [[MusicRoomViewController alloc]init];


    // 包装导航控制器

    UINavigationController *musicNav = [[UINavigationController alloc]initWithRootViewController:musicVC];


    // 创建标签按钮

    UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:@"音乐馆" image:[UIImage imageNamed:@"musicLibrary"] selectedImage:[UIImage imageNamed:@"musicLibrary_Highlighted"]];


    // 将按钮赋值给当前控制器的标签按钮

    musicNav.tabBarItem = item2;



    // ======= 发现 ========

    // 创建页面

    FindViewController *findVC = [[FindViewController alloc]init];


    // 包装导航控制器

    UINavigationController *findNav = [[UINavigationController alloc]initWithRootViewController:findVC];


    // 创建标签按钮

    UITabBarItem *item3 = [[UITabBarItem alloc]initWithTitle:@"发现" image:[UIImage imageNamed:@"find"] selectedImage:[UIImage imageNamed:@"find_Highlighted"]];


    // 将按钮赋值给当前控制器的标签按钮

    findNav.tabBarItem = item3;



    // ======= 更多 ========

    // 创建页面

    MoreViewController *moreVC = [[MoreViewController alloc]init];


    // 包装导航控制器

    UINavigationController *moreNav = [[UINavigationController alloc]initWithRootViewController:moreVC];


    // 创建标签按钮

    UITabBarItem *item4 = [[UITabBarItem alloc]initWithTitle:@"更多" image:[UIImage imageNamed:@"more_Highlighted"] selectedImage:[UIImage imageNamed:@"more_Highlighted"]];


    // 将按钮赋值给当前控制器的标签按钮

    moreNav.tabBarItem = item4;



    // 将四个导航控制器添加到标签控制器中

    self.viewControllers = @[myNav,musicNav,findNav,moreNav];

你可能感兴趣的:(UITabBar)