iphone中UINavigationBar(导航条视图)的介绍
2015-09-12 12:25
633 查看
多视图应用程序中,我们常常使用到自定义UINavigationBar来完成导航条的设置。
1.创建一个导航条
2.有了导航条以后,必须在导航条上设置一个item集合,用来放置中间的标题,和左右的按钮,因为上面空间有限,只有左右两个按钮。
//创建一个导航条集合
分别有如下几种样式:
从字面我们就能了解这4种样式的大概意思:
分别为:
UIBarStyleDefault:默认样式
UIBarStyleBlack:黑色
UIBarStyleBlackOpaque:黑色不透明
UIBarStyleBlackTranslucent:黑色透明
注意:我们发现,在后面两个标记为Deprecated,我们知道使用后面两种将不被提倡。
从枚举中,我们也可以看出:UIBarStyleBlack=1和UIBarStyleBlackOpaque=1表示为一样的。
后来,发现增加了一个方法:[navBar setTranslucent:YES];用来指示是否透明。
所以,我们使用UIBarStyleDefault和UIBarStyleBlack来定义UINavigationBar样式,并且用setTranslucent:方法来设置透明与否。
3.自定义导航条颜色
如果,仅仅使用这4种(2种样式*是否透明),难免太逊了,必须能自定义UINavigationBar样式啊。
[navBar setBackgroundImage:[UIImage imageNamed: @"图片名称"] forBarMetrics:UIBarMetricsDefault];
setBackgroundImage方法的第二个参数,需要解释一下:
UIBarMetricsDefault:用竖着(拿手机)时UINavigationBar的标准的尺寸来显示UINavigationBar
UIBarMetricsLandscapePhone:用横着时UINavigationBar的标准尺寸来显示UINavigationBar
1.创建一个导航条
UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
2.有了导航条以后,必须在导航条上设置一个item集合,用来放置中间的标题,和左右的按钮,因为上面空间有限,只有左右两个按钮。
//创建一个导航条集合
UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:nil];3.设置导航条样式(使用系统自带样式)
[navBar setBarStyle:UIBarStyleDefault];
分别有如下几种样式:
typedef NS_ENUM(NSInteger, UIBarStyle) { UIBarStyleDefault = 0, UIBarStyleBlack = 1, UIBarStyleBlackOpaque = 1, // Deprecated. Use UIBarStyleBlack UIBarStyleBlackTranslucent = 2, // Deprecated. Use UIBarStyleBlack and set the translucent property to YES };
从字面我们就能了解这4种样式的大概意思:
分别为:
UIBarStyleDefault:默认样式
UIBarStyleBlack:黑色
UIBarStyleBlackOpaque:黑色不透明
UIBarStyleBlackTranslucent:黑色透明
注意:我们发现,在后面两个标记为Deprecated,我们知道使用后面两种将不被提倡。
从枚举中,我们也可以看出:UIBarStyleBlack=1和UIBarStyleBlackOpaque=1表示为一样的。
后来,发现增加了一个方法:[navBar setTranslucent:YES];用来指示是否透明。
所以,我们使用UIBarStyleDefault和UIBarStyleBlack来定义UINavigationBar样式,并且用setTranslucent:方法来设置透明与否。
3.自定义导航条颜色
如果,仅仅使用这4种(2种样式*是否透明),难免太逊了,必须能自定义UINavigationBar样式啊。
[navBar setBackgroundImage:[UIImage imageNamed: @"图片名称"] forBarMetrics:UIBarMetricsDefault];
setBackgroundImage方法的第二个参数,需要解释一下:
UIBarMetricsDefault:用竖着(拿手机)时UINavigationBar的标准的尺寸来显示UINavigationBar
UIBarMetricsLandscapePhone:用横着时UINavigationBar的标准尺寸来显示UINavigationBar
相关文章推荐
- iOS学习之KVC中setValuesForKeysWithDictionary:
- UI:关于RGB与16进制颜色值的转换
- 【转】SoapUI5.0创建WebService接口模拟服务端
- UITableView中自定义Cell,自适应高度
- 给NGUI上的预设体动态添加点击事件
- leetcode: Distinct Subsequences
- EQueue文件持久化消息关键点设计思路
- setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key lable1.'
- UIpickerView
- @PathVariable和@RequestParam的区别
- JPA字段映射(uuid,日期,枚举,@Lob)
- Leetcode_232_Implement Queue using Stacks
- Lettcode_232_Implement Queue using Stacks
- 用block改写UIButton点击事件和UIAlerView的按钮点击代理方法
- [iOS UI进阶 - 5.0] 手势解锁Demo
- 【Java】_图形用户界面(GUI)
- 注意uiview的两个重绘函数
- UI中一系列 个人错误总结
- [Leetcode]Closest Binary Search Tree Value
- [Leetcode]Closest Binary Search Tree Value II