UINavigationController和UITabBarController
来源:互联网 发布:linux xampp 启动界面 编辑:程序博客网 时间:2024/04/28 00:50
UINavigationController,展示上方的导航栏;UITabBarController,展示下方的tab栏。这2个组件都用得挺多
其实还有一个UIToolBar,可以单独使用,不过目测不太常用
container controller
UINavigationController和UITabBarController,都属于container controller。用来容纳实际承载业务的ViewController
UIViewController *first = [[FirstViewController alloc] init];UINavigationController *contactNav = [[UINavigationController alloc] initWithRootViewController:first];
UITabBarController *tab = [[UITabBarController alloc] init]; UIViewController *first = [[FirstViewController alloc] init];UINavigationController *contactNav = [[UINavigationController alloc] initWithRootViewController:first]; UIViewController *second = [[SecondViewController alloc] init];UINavigationController *reportNav = [[UINavigationController alloc] initWithRootViewController:second]; tab.viewControllers = @[contactNav, reportNav];
如果既需要导航栏,又要下方的tab栏,就可以用这个方法。先把实际的ViewController装到NavigationController里,再把NavigationController装到TabBarController里
控制导航栏和tab栏
控制导航栏和tab栏的按钮,不是由container controller自己做的,而是由实际的ViewController负责的,ios的这个设计比较灵活,可以实现同一个Navigation里的ViewController有各自独立的导航栏按钮,API也不复杂
UIBarButtonItem *logo = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"logo"] style:UIBarButtonItemStylePlain target:self action:@selector(logoPressed:)];self.navigationItem.leftBarButtonItem = logo; UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];UIBarButtonItem *search = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:nil action:nil];NSArray *rightButtons = [[NSArray alloc] initWithObjects:add, search, nil];self.navigationItem.rightBarButtonItems = rightButtons;self.title = @"通讯录首页"; self.tabBarItem.image = [UIImage imageNamed:@"logo"];self.tabBarItem.title = @"通讯录";
通过ViewController自带的property navigationItem,就可以分别设置左边和右边的按钮了。如果ViewController没有包含在NavigationController里,这个属性貌似为nil。title是在nav栏上显示的文字。tabBarItem是用来控制tab栏的显示,可以设置image和titile
0 0
- UINavigationController和UITabBarController合用。
- UINavigationController和UITabBarController合用
- UINavigationController和UITabBarController合用。
- 隐藏UINavigationController和UITabBarController
- UITabBarController和UINavigationController混用
- UINavigationController和UITabBarController合用。
- UINavigationController和UITabBarController
- UINavigationController和UITabBarController混用
- UItabBarController和UINavigationController结合使用
- UINavigationController和UITabBarController的集成
- UITabBarController 和 UINavigationController 的 popToRootViewController
- iOS 自定义UINavigationController和UITabBarController
- UINavigationController和UITabbarController内部结构解析
- UITabBarController和UINavigationController搭配使用
- UINavigationController跳转到UITabBarController和UITabBarController跳转到 UINavigationController
- UINavigationController跳转到UITabBarController和UITabBarController跳转到 UINavigationController
- UINavigationController,UITabBarController
- UINavigationController, UITabBarController
- 好用的xshell颜色配置
- iOS开发- 隐藏键盘总结
- 集团信息化“润物细无声”
- mysql fabric
- 数据库的基本操作
- UINavigationController和UITabBarController
- 提高 Varnish 的效率:去除不需要的 Cookies 和 QueryStrings
- 树的遍历总结
- fio编译错误一例
- java GC时机
- 栈区,堆区,全局区,文字常量区,程序代码区 内存详解
- JAVA邮件发送的简单实现
- 黑马程序员_学习笔记06-框架集
- Cut or Delete the Current Line in Visual Studio