分栏控制器-UITabBarController

UITableBarController是选项卡栏导航控制器,显示效果是在页面底部,有多个选项卡,通过点击不同的选项卡可以在不同的ViewController之间切换
首先要先创建几个ViewController
在AppDelegate.m文件中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    //创建windou
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    //显示window
    [self.window makeKeyAndVisible];
    
    //创建控制器一
    ViewC1 *vcFirst = [[ViewC1 alloc] init];
    ViewC2 *vcSecond = [[ViewC2 alloc] init];
    ViewC3 *vcThird = [[ViewC3 alloc] init];
    
    vcFirst.title = @"首页";
    vcSecond.title = @"搜索";
    vcThird.title = @"个人";
    
    vcFirst.view.backgroundColor = [UIColor blueColor];
    vcSecond.view.backgroundColor = [UIColor orangeColor];
    vcThird.view.backgroundColor = [UIColor whiteColor];
    
    //创建分栏控制器
    UITabBarController *tb= [[UITabBarController alloc] init];
    
    //设置分栏控制器整体颜色
    tb.tabBar.tintColor = [UIColor greenColor];
    
    //创建一个控制器数组对象
    NSArray *arryVC = [NSArray arrayWithObjects:vcFirst, vcSecond, vcThird, nil];
    
    //将分栏控制器赋值
    tb.viewControllers = arryVC;
    //将分栏控制器作为根控制器
    self.window.rootViewController = tb;
    
    return YES;
}

然后在ViewContrlooer中设置显示效果

#import "ViewC1.h"

@interface ViewC1 ()

@end

@implementation ViewC1

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //设置点击的图像
    UIImage *image = [UIImage imageNamed:@"发现.png"];
    
    UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:@"发现" image:nil tag:101];
    
    tabBarItem.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    tabBarItem.selectedImage = [[UIImage imageNamed:@"音乐2.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.tabBarItem = tabBarItem;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

#import "ViewC2.h"

@interface ViewC2 ()

@end

@implementation ViewC2

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIImage *image = [UIImage imageNamed:@"视频.png"];
    UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:@"视频" image:nil tag:30];
    tabBarItem.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem.selectedImage = [[UIImage imageNamed:@"视频2.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.tabBarItem = tabBarItem;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

#import "ViewC3.h"

@interface ViewC3 ()

@end

@implementation ViewC3

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIImage *image = [UIImage imageNamed:@"我的.png"];
    UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:nil tag:101];
    tabBarItem.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem.selectedImage = [[UIImage imageNamed:@"音符 2.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.tabBarItem = tabBarItem;
    
}

显示效果如下
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值