APP开发之UINavigationController设置
来源:互联网 发布:淘宝打假怎么赚钱 编辑:程序博客网 时间:2024/06/07 23:34
前言:
搭建APP的时候少不了设置UITabBarController,UINavigationController;
UITabBarController是为了管理控制器,而UINavigationController是为了统一布局;
本篇介绍导航控制器,主要涉及到以下“控件”的设置
一、UINavigationBar
1、导航控制器的整个背景颜色
self.navigationBar.barTintColor = [UIColor redColor];//设置为红色
2、设置文字颜色和大小
// 设置UINavigationBar文字属性 UINavigationBar *appearance = [UINavigationBar appearance]; NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary]; textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:18]; textAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor]; [appearance setTitleTextAttributes:textAttrs];
二、UIBarButtonItem
这里分一般和自定义进行设置:
1、一般情况:(与设置UINavigationBar一样)
UIBarButtonItem *appearance = [UIBarButtonItem appearance]; NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary]; textAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor]; [appearance setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
2、自定义:重写导航控制器的 pushViewController 方法
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{ if (self.viewControllers.count > 0) { /** 推出控制器之后隐藏tabBar */ viewController.hidesBottomBarWhenPushed = YES; viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem barButtonItemWithBg:@"icon_return" title:@"返回" target:self action:@selector(back)]; **这里对BarButtonItem进行自定义** } [super pushViewController:viewController animated:YES]; }-(void)back{ [self popViewControllerAnimated:YES]; }
对BarButtonItem进行扩展
+ (UIBarButtonItem *)barButtonItemWithBg:(NSString *)bg title:(NSString *)title target:(id)target action:(SEL)action{ UIButton *button = [[UIButton alloc]init]; [button setImage:[UIImage imageNamed:bg] forState:UIControlStateNormal]; [button setImageEdgeInsets:UIEdgeInsetsMake(0, -30, 0, 0)]; [button setTitle:title forState:UIControlStateNormal]; [button setTitleEdgeInsets:UIEdgeInsetsMake(0, -55, 0, 0)]; [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; button.titleLabel.font = [UIFont systemFontOfSize:14]; button.frame = CGRectMake(0, 0, 60, 44); [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; return [[UIBarButtonItem alloc] initWithCustomView:button];}
1 0
- APP开发之UINavigationController设置
- IOS开发之UINavigationController
- APP开发之UIStatusBarStyle设置
- APP开发之UITabBarController设置
- iOS APP开发整理--UITabBarController,UINavigationController
- IOS开发之UINavigationController详解
- IOS开发之UINavigationController详解
- IOS开发基础之UINavigationController
- Android开发之设置APP全局字体
- UINavigationController设置
- ios菜鸟之路:标题栏UINavigationcontroller开发
- IOS开发(7)之UINavigationController导航
- IOS开发之UINavigationController的学习体会
- iOS开发之UINavigationController(一)
- iOS开发之UINavigationController(二)
- iOS开发之UINavigationController的使用
- 【iOS开发-UITabBarController】UITabBarController上面的UINavigationController的设置
- Windows App开发之集成设置、帮助、搜索和共享
- java 多线程编程之CountDownLatch
- iOS block反向传值
- LW教你自定义安卓控件之LoadingView
- python正则--简单匹配身份证号
- 字符串匹配之有限自动机
- APP开发之UINavigationController设置
- 多行文本溢出显示省略号(…)全攻略
- SQL Server启动,关闭的bat
- Logger日志级别说明及设置方法、说明
- 浅析哈尔级联人脸检测与混合整数线性规划
- 高并发高负载网站系统架构
- 自学oricle第一天--用户权限
- 第五章 守护进程
- 文件复制C语言实现