iOS基础之UITabBarController(标签视图控制器)
2016-02-21 22:30
274 查看
UITabBarController是可以帮我们添加、管理许多的标签项,使我们的程序包含不同的操作模式,由于管理UITabBar可能比较麻烦,系统帮我们对其进行了封装,产生了简单好用的UITabBarController--标签视图控制器。
代码演示:
总之它可以用标签管理多个页面,非常的方便,很多软件都用到它。
代码演示:
#import "AppDelegate.h" #import "FirstViewController.h" #import "SecondViewController.h" #import "ThirdViewController.h" #import "FourthViewController.h" @interface AppDelegate () @end @implementation AppDelegate -(void)dealloc{ [_window release]; [super dealloc]; } - (void)change{ [[UITabBar appearance]setTintColor:[UIColor greenColor]]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; FirstViewController *firstVC = [[FirstViewController alloc]init]; firstVC.tabBarItem.title = @"帅哥";//设置显示的文本 // firstVC.tabBarItem.badgeValue = @"爱好";//设置显示角标 [firstVC.button addTarget:self action:@selector(change) forControlEvents:UIControlEventTouchUpInside]; firstVC.tabBarItem.image = [[UIImage imageNamed:@"iconfont-cool"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; //设置图标 /* 第一个参数为标签显示的文本 第二个参数正常状态下显示的图片 第三个参数选中状态下显示的图片 注意,图片想要正常显示,必须是png类型 */ SecondViewController *secondVC = [[SecondViewController alloc]init]; UITabBarItem *item = [[UITabBarItem alloc]initWithTitle:@"何二" image:[UIImage imageNamed:@"iconfont-douyixia"] selectedImage:[UIImage imageNamed:@"iconfont-xu"]]; // 创建好标签之后指定为某一个视图控制器的标签 secondVC.tabBarItem = item; [item release]; //系统自带图标 ThirdViewController *thirdVC = [[ThirdViewController alloc]init]; UITabBarItem *systemItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:101]; thirdVC.tabBarItem = systemItem; [systemItem release]; /* 第一个参数显示文本 第二个参数正常状态下显示的图片 第三个参数标记值 */ FourthViewController *fourthVC = [[FourthViewController alloc]init]; UITabBarItem *commomItem = [[UITabBarItem alloc]initWithTitle:@"洪荒" image:[UIImage imageNamed:@"iconfont-zhu"] tag:102]; fourthVC.tabBarItem = commomItem; //一键换肤 [[UITabBar appearance]setTintColor:[UIColor redColor]]; UINavigationController *naVC = [[UINavigationController alloc]initWithRootViewController:firstVC]; //创建标签视图控制器 UITabBarController *tabbarController = [[UITabBarController alloc]init]; //设置标签视图控制器需要管理的子视图控制器 tabbarController.viewControllers = @[naVC,secondVC,thirdVC,fourthVC]; // tabbarController.selectedIndex = 1; //指定window的根视图控制器为标签视图控制器 self.window.rootViewController = tabbarController; [firstVC release]; [secondVC release]; [thirdVC release]; [fourthVC release]; [naVC release]; [tabbarController release];
总之它可以用标签管理多个页面,非常的方便,很多软件都用到它。
相关文章推荐
- 将U-Boot、uImage和rootfs烧入iMX53系统的4GB SD卡
- Question and Answer
- Request的getParameter和getAttribute方法的区别
- 不懂前端的程序员不是好美工——UI框架metronic使用教程——程序员视角
- IOS-OC-基本控件之UITextField
- HDU_1711_NumberSequence
- IOS-UI-基本控件之UITextField
- iOS-UI-基本控件之UITextField
- 集成TFS Build生成与SonarQube获取代码分析结果
- Android UI效果之绘图篇(一)
- iOS关于CAShapeLayer与UIBezierPath的知识内容
- JSP request对象
- 放肆地使用UIBezierPath和CAShapeLayer画各种图形
- 1.1配置apue.h
- ios UIImageView详解
- iOS基础之UIScrollView(滚动视图)
- JAVA UUID 生成
- KVC之-(void)setValue:(id)value forUndefinedKey:(NSString *)key
- - (void)setValue:(id)value forKey:(NSString *)key方法,实现原理与验证
- deque双向队列(转)