UI常用方法总结之 UINavigationController
2015-05-29 16:37
330 查看
UINavigationController :UIViewController
1.创建UINavigationController对象
UINavigationController *navCV = [[UINavigationControlleralloc]initWithRootViewController:mainVC];
通常和
self.window.rootViewController = navCV;
连用
2.- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
推出第二个页面
eg:[self.navigationControllerpushViewController:secondVC animated:YES];
3.- (UIViewController *)popViewControllerAnimated:(BOOL)animated;
返回上一视图
eg:[self.navigationControllerpopViewControllerAnimated:YES];
4.- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;
返回指定视图
eg:获得viewController的栈
UIViewController *viewC = [self.navigationController.viewControllersobjectAtIndex:0];
[self.navigationController popToViewController:viewC animated:YES];
5.- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated;
返回根视图
eg:[self.navigationControllerpopToRootViewControllerAnimated:YES];
UINavigationItem :NSObject <NSCoding>
每个页面要显示在导航栏上的内容(标题,两边按钮信息)
1.rightBarButtonItem
创建导航栏右边按钮
参数1选择一个系统提供的图标信息
eg:self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(button:)]autorelease];
2.leftBarButtonItem
创建导航栏左边按钮
eg:self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-yinle.png"] style:UIBarButtonItemStylePlain target:self action:@selector(button:)]autorelease];
3.hidesBackButton
隐藏返回按钮
eg:self.navigationItem.hidesBackButton =YES;
4.titleView
标题相关设置
eg:self.navigationItem.titleView = [[[UISegmentedControlalloc]initWithItems:@[@"111",@"222"]]autorelease];
UINavigationbar
1.translucent
是否透明
eg:self.navigationController.navigationBar.translucent =YES;
2.barTintColor
bar的颜色eg:self.navigationController.navigationBar.barTintColor = [UIColor grayColor];
3.setNavigationBarHidden
隐藏bar
e.g.:[self.navigationControllersetNavigationBarHidden:NO];
4.automaticallyAdjustsScrollViewInsets
取消掉scrollView的系统设置的UIEdgeInsets
e.g.:elf.automaticallyAdjustsScrollViewInsets =YES;
(当页面出现不可预知问题时可以尝试使用这个开关)
5.setBackgroundImage
设置bar背景图片
eg:[self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"2.png"]forBarMetrics:UIBarMetricsDefault];
2、iOS Foundation框架简介1 常用结构体的用法和输出
3、Cocos2dx小技巧(五)常用宏介绍
4、IOS运行时(常用函数)
5、使用Sass预定义一些常用的样式
6、iOS应用数据存储的常用方式
7、常用的自定义UI组件-一:TimeView
8、iOS常用加密方式
1.创建UINavigationController对象
UINavigationController *navCV = [[UINavigationControlleralloc]initWithRootViewController:mainVC];
通常和
self.window.rootViewController = navCV;
连用
2.- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
推出第二个页面
eg:[self.navigationControllerpushViewController:secondVC animated:YES];
3.- (UIViewController *)popViewControllerAnimated:(BOOL)animated;
返回上一视图
eg:[self.navigationControllerpopViewControllerAnimated:YES];
4.- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;
返回指定视图
eg:获得viewController的栈
UIViewController *viewC = [self.navigationController.viewControllersobjectAtIndex:0];
[self.navigationController popToViewController:viewC animated:YES];
5.- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated;
返回根视图
eg:[self.navigationControllerpopToRootViewControllerAnimated:YES];
UINavigationItem :NSObject <NSCoding>
每个页面要显示在导航栏上的内容(标题,两边按钮信息)
1.rightBarButtonItem
创建导航栏右边按钮
参数1选择一个系统提供的图标信息
eg:self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(button:)]autorelease];
2.leftBarButtonItem
创建导航栏左边按钮
eg:self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-yinle.png"] style:UIBarButtonItemStylePlain target:self action:@selector(button:)]autorelease];
3.hidesBackButton
隐藏返回按钮
eg:self.navigationItem.hidesBackButton =YES;
4.titleView
标题相关设置
eg:self.navigationItem.titleView = [[[UISegmentedControlalloc]initWithItems:@[@"111",@"222"]]autorelease];
UINavigationbar
1.translucent
是否透明
eg:self.navigationController.navigationBar.translucent =YES;
2.barTintColor
bar的颜色eg:self.navigationController.navigationBar.barTintColor = [UIColor grayColor];
3.setNavigationBarHidden
隐藏bar
e.g.:[self.navigationControllersetNavigationBarHidden:NO];
4.automaticallyAdjustsScrollViewInsets
取消掉scrollView的系统设置的UIEdgeInsets
e.g.:elf.automaticallyAdjustsScrollViewInsets =YES;
(当页面出现不可预知问题时可以尝试使用这个开关)
5.setBackgroundImage
设置bar背景图片
eg:[self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"2.png"]forBarMetrics:UIBarMetricsDefault];
延伸阅读:
1、Objective-C Http常用API 同步请求与异步请求2、iOS Foundation框架简介1 常用结构体的用法和输出
3、Cocos2dx小技巧(五)常用宏介绍
4、IOS运行时(常用函数)
5、使用Sass预定义一些常用的样式
6、iOS应用数据存储的常用方式
7、常用的自定义UI组件-一:TimeView
8、iOS常用加密方式
相关文章推荐
- XHNewsFrameworkExample
- Android QuickContactBadge
- Android QuickContactBadge
- 10.2 NSOperation/NSOperationQueue:提供了一些在GCD中不容易实现的特性,如:限制最大并发数量,操作之间的依赖关系.
- 使用xcodebuild命令行编译iOS应用遇到的一个错误及解决办法
- easyui datagrid中动态改变某行的颜色
- ios8 UITableView设置 setSeparatorInset:UIEdgeInsetsZero不起作用的解决办法
- UIScrollView滚动到制定的位置
- easyUI中datagrid如何展示对象下属性的多个子属性
- iOS之默认搜索UISearchDisplayController
- iOS真机UI调试利器——Reveal(在原转载上有所修改)
- VDI ipad通过AD+Raduis认证配置
- 解决Mygui不支持中文路径
- android出现the project was not built due to "a resource exists with a different case问题
- @RequestParam的作用
- 漂亮UI的全能音乐播放器
- Android UI开发第十四篇——可以移动的悬浮框
- SharePoint 2013 隐藏左边快速启动菜单栏(Hiding the Quick Launch Bar)
- iOS多线程编程之NSOperation和NSOperationQueue的使用
- iOS使用UITableView从plist中选择省市区