No.10 Xcode(5.1.x) UITabBarController
来源:互联网 发布:usb摄像头和网络摄像头 编辑:程序博客网 时间:2024/06/05 15:48
1.UITabBarController和UINavigationController是系统提供的两种视图控制器, 它们一定程度上代表了程序的流程结构, 他们也可以混合在一起使用, 混合时最好将UINavigationController作为UITabBarController的子控制器;
2.tabBar.translucent=NO时, 子控制器的视图不会被UITabBarController的控制栏遮挡;
3.子控制器的tabBarItem, 会作为UITabBarController的控制栏的一个项来显示. 子控制器的title属性, 与tabBarItem.title属性, 都能影响到控制栏的标题文字;
4.子控制器的tabBarItem的 [setFinishedSelectedImage: withFinishedUnselectedImage:] 方法, 在iOS7中被换成了 [initWithTitle: image: selectedImage:] 方法, iOS7中的UIImage参数需要使用 [imageWithRenderingMode:] 方法加工后, 才能显示正常;
5.子控制器的tabBarItem的选中和未选中图标, 要求尺寸是30x30, 才会正常显示;
创建UITabBarController时
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ UINavigationController* naviController0 = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] initWithTitle:@"Page0"]]; naviController0.navigationBar.translucent = NO; // 可以换成YES测试下效果 UINavigationController* naviController1 = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] initWithTitle:@"Page1"]]; naviController1.navigationBar.translucent = NO; UINavigationController* naviController2 = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] initWithTitle:@"Page2"]]; naviController2.navigationBar.translucent = NO; UITabBarController* tabBarController = [[UITabBarController alloc] init]; tabBarController.viewControllers = @[naviController0, naviController1, naviController2]; tabBarController.tabBar.translucent = NO; // 可以换成YES测试下效果 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = tabBarController; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES;}
子控制器中
- (id)initWithTitle:(NSString*)title{ self = [super init]; if (self) { // 把这段代码移到 [viewDidLoad] 中, 可以测试下效果 UITabBarItem* tabBarItem = [[UITabBarItem alloc] init]; tabBarItem.badgeValue = @"xyz"; // 右上图标 tabBarItem.title = title; // 标题文字 tabBarItem.image = [[UIImage imageNamed:@"fruit-apple0.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; // 选中与未选中时的图片, 尺寸必须是30x30 tabBarItem.selectedImage = [[UIImage imageNamed:@"fruit-apple1.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; // iOS7中的方法 [tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"fruit-apple0.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"fruit-apple1.png"]]; // iOS6以前的方法 self.title = title; self.tabBarItem = tabBarItem; } return self;}- (void)viewDidLoad{ [super viewDidLoad]; self.view.layer.borderColor = [UIColor redColor].CGColor; self.view.layer.borderWidth = 2.0; self.view.layer.masksToBounds = YES;}
0 0
- No.10 Xcode(5.1.x) UITabBarController
- No.06 Xcode(5.1.x) UINavigationController
- No.08 Xcode(5.1.x) 使用FFmpeg
- No.14 Xcode(5.1.x) socket
- No.15 Xcode(5.1.x) libxml2
- No.03 Xcode(5.1.x) c,c++,objiective-c混编
- No.05 Xcode(5.1.x) 服务器消息推送
- No.11 Xcode(5.1.x) 设备或程序旋转
- No.12 Xcode(5.1.x) NSString, NSArray 和 NSDictionary
- No.13 Xcode(5.1.x) 获取设备信息, 系统信息
- No.07 Xcode(5.x) 使用SQLite
- No.09 Xcode(5.x) UITextField
- No.01 Xcode(7.x) 键盘
- No.04 Xcode(7.x) GCD相关
- No.04 Xcode(7.x) 蓝牙
- No.01 Xcode(5.1.x) 在Vmware中安装Mac OS X 10.8
- No.04 Xcode(5.x) app的测试与发布
- No.02 Xcode(7.x) 横竖屏旋转
- ios 推送
- 开启线程
- android Touch事件传递自己理解
- 相机闪存卡数据恢复方法/数码相机误删照片恢复详解
- POJ 3566
- No.10 Xcode(5.1.x) UITabBarController
- Hdu 1043
- POJ 1009 Edge Detection(模拟)
- 如何使用KeyChain保存和获取UDID
- Digital Roots——ZOJ 1115
- vc6.0与vs2010库文件添加
- C语言的本质(23)——C标准库之输入与输出(上)
- dfadfafa
- 批处理中set截取字符详解