UITabBarController 笔记(一)AppDelegate中加UITabBarController 为 rootViewController
2015-12-01 13:37
399 查看
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; //初始化 tabBarItem对应的ViewController UIViewController *viewCtrl1 = [[UIViewController alloc] init]; viewCtrl1.title = @"first viewctrl"; viewCtrl1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"rename first" image:nil tag:1];//自己定义tabBarItem是在对应的ViewController中去做 viewCtrl1.view.backgroundColor = [UIColor blueColor]; UIViewController *viewCtrl2 = [[UIViewController alloc] init]; viewCtrl2.title = @"second viewctrl"; viewCtrl2.view.backgroundColor = [UIColor yellowColor]; viewCtrl2.tabBarItem.badgeValue = @"360"; UIViewController *viewCtrl3 = [[UIViewController alloc] init]; viewCtrl3.title = @"3 viewctrl"; viewCtrl3.view.backgroundColor = [UIColor colorWithRed:0.1 green:0.2 blue:0.3 alpha:1.0]; UIViewController *viewCtrl4 = [[UIViewController alloc] init]; viewCtrl4.title = @"4 viewctrl"; viewCtrl4.view.backgroundColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.3 alpha:1.0]; UIViewController *viewCtrl5 = [[UIViewController alloc] init]; viewCtrl5.title = @"5 viewctrl"; viewCtrl5.view.backgroundColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.7 alpha:1.0]; UIViewController *viewCtrl6 = [[UIViewController alloc] init]; viewCtrl6.title = @"6 viewctrl"; viewCtrl6.view.backgroundColor = [UIColor colorWithRed:0.6 green:0.5 blue:0.7 alpha:1.0]; UIViewController *viewCtrl7 = [[UIViewController alloc] init]; viewCtrl7.title = @"7 viewctrl"; viewCtrl7.view.backgroundColor = [UIColor colorWithRed:0.9 green:0.5 blue:0.3 alpha:1.0]; // tabBarCtrl = [[UITabBarController alloc] init]; tabBarCtrl.viewControllers = [NSArray arrayWithObjects:viewCtrl1, viewCtrl2 ,viewCtrl5, viewCtrl3, viewCtrl4, viewCtrl6, viewCtrl7, nil];//添加viewcontrollers, 数组顺序就是tabBarItem对应的viewController顺序 tabBarCtrl.customizableViewControllers = [NSArray arrayWithObjects: viewCtrl2 ,viewCtrl3, viewCtrl5, viewCtrl7, nil]; //显示可编辑的有那些viewcontroller [tabBarCtrl setSelectedIndex: 3];//设置选中的是那个tabBarItem,如果为无效的index,则默认选中第一个 tabBarCtrl.view.frame = CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height); self.window.rootViewController = tabBarCtrl; [self.window makeKeyAndVisible]; return YES; } 关于旋转 UITabBarController默认只支持竖屏,当设备方向放生变化时候,它会查询viewControllers中包含的所有ViewController,仅当所有的viewController都支持该方向时,UITabBarController才会发生旋转,否则默认的竖向。UITabBarController支持旋转,而且发生旋转的时候,只有当前显示的viewController会接收到旋转的消息。 关于 UITabBarControllerDelegate 委托 //设置用户是否可以选中,如果返回NO,用户不能选中,但代码中还可以用tabBarCtrl setSelectedIndex: 3]选中 - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController; { return YES; } //选中后的消息响应 - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { } more 中edit监测 - (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers; - (void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed; - (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed;
相关文章推荐
- 《swift2.0 官方教程中文版》 第2章-13继承
- 如何在xcode7上免开发者账号进行ios程序真机测试
- Github上的600多个iOS开源类库
- Execution failed for task ':app:processDebugManifest'
- Swift 值类型,引用类型,深拷贝,浅拷贝,Copy,MutableCopy
- android-serialport-api and libusb for android
- Android ListView中嵌入其实组件后如checkbox,button后ItemClick事件失效的问题
- android-Media Playback
- MPAndroidChart的K线图上添加均线
- MPAndroidChart的K线图上添加均线
- Android-Media and Camera
- Android 开发知识收藏夹
- Android 中的 Service 全面总结
- Android之TabHost布局
- iOS中解析 XML / JSON
- Android控件之TimePickerDialog
- Tizen web app开发示例(将2048移植到Tizen平台上)
- iOS_ARC下需要release 的情况
- Curses library not found. Please install appropriate package
- unity 游戏公告跑马灯循环播放的效果