您好,欢迎来到知库网。
搜索
您的当前位置:首页iOS学习之UITabbarController详解

iOS学习之UITabbarController详解

来源:知库网

//实例化标签

UITabBarController * tabbarVC = [[UITabBarControlleralloc] init];

//修改tintColor

tabbarVC.tabBar.tintColor = [UIColorcyanColor];

//修改barTintColor

tabbarVC.tabBar.barTintColor = [UIColor orangeColor];

标签按钮实例化

UITabBarItem* item1 = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:0];

标签右上数字显示方法

item1.badgeValue =

@"100";

给按钮添加图片以及点击后图片

UIImage * coll1 = [[UIImage imageNamed:@"tab_c1"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

UIImage * coll2 = [[UIImage imageNamed:@"tab_1"]

imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//保持图片不被渲染吧

UITabBarItem * item3 = [[UITabBarItemalloc] initWithTitle:@"收藏" image:coll1selectedImage:coll2];

第一种添加子控制器的方法

//[tabbarVCaddChildViewController:vc1];

//[tabbarVCaddChildViewController:vc2];

//第二种添加子控制器的方法

tabbarVC.viewControllers = @[vc1,vc2,vc3,vc4,vc5];

设置tabbar为根控制器。

设置全局控件

UITabBar * tab =

[UITabBar appearance];

UITabBarItem * item =

[UITabBarItem appearance];

设置全局的tabbar

NSMutableArray *controllNames = [NSMutableArrayarrayWithArray:@[@"First",@"Second",@"Third"]];

NSArray * titles = @[@"第一页",@"第二页",@"第三页"];

for (NSUIntegeri = 0; i < controllNames.count; i++) {

//获取controller拼接后的名字

NSString* controllName = [controllNames[i]stringByAppendingString:@"ViewController"];

//将字符串转换成Class类型实例UIViewController

UIViewController * vc = [[NSClassFromString(controllName) alloc] init];

vc.title= titles[i];

BaseNavViewController * nav = [[BaseNavViewController alloc]initWithRootViewController:vc];

//根据索引值替换可变数组元素

[controllNames replaceObjectAtIndex:i withObject:nav];

}

self.viewControllers = controllNames;

当导航栏跳转时隐藏tabbar

vc.hidesBottomBarWhenPushed = YES;

Copyright © 2019- zicool.com 版权所有 湘ICP备2023022495号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务