UINavigationBar
来源:互联网 发布:万能电子狗升级软件 编辑:程序博客网 时间:2024/05/17 13:40
UINavigationBar是用于实现管理层级关系内容的组件,直接继承自UIView。通常用在UINavgationController类中,用于管理和显示UINavgationController的subViewController , 同时UINavgationBar也可以单独使用,添加至任何的UIView中。UINavigationBar比较重要的属性为,左侧按钮,中间的标题,以及右侧按钮。
1、UINavigationBar的创建
UINavigationBar * navigationBarDefault = [[UINavigationBaralloc]initWithFrame:CGRectMake(0,40,320,40)];
2、设置UIBarStyle
typedef enum {
UIBarStyleDefault = 0,//对应一个蓝色渐变背景
UIBarStyleBlack = 1,//对应一个不透明的褐色背景样式。
UIBarStyleBlackOpaque = 1, // Deprecated 等用于UIBarStyleBlack样式,但规定为弃用类型
UIBarStyleBlackTranslucent = 2, // Deprecated等用于barStyle设置为UIBarStyleBlack,同时指定translucent属性为YES,规定为弃用类型。
} UIBarStyle;
navigationBarDefault.barStyle =UIBarStyleDefault;
3、添加UINavigationItem
UINavgationBar虽然直接继承于UIView,但其本身并不是同其它UIView一样通过addSubview去添加内容,比较特殊的是,需要通过navgation item类向其补充指定的 内容,包括按钮和标题。究其原因是在设计上UINavgationBar是通过维护一个UINavgationItem对象栈来实现管理具有层级关系的视图内容。通过
- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated;
- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated;// Returns the item that was popped.
- (void)setItems:(NSArray *)items animated:(BOOL)animated;// If animated is YES, then simulate a push or pop depending on whether the new top item was previously in the stack.
UINavigationItem * defaultItem = [[UINavigationItemalloc]initWithTitle:@"默认导航栏"];
[navigationBarDefault setItems:[NSArray arrayWithObjects:defaultItem,nil]];
4、设置左右button
通过设置UINavigation的左右button来设置UINavigationBar的左右button
UIBarButtonItem * leftDefaultButton = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarkstarget:selfaction:nil];
defaultItem.leftBarButtonItem = leftDefaultButton;
UIBarButtonItem * rightDefaultButton = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCameratarget:selfaction:nil];
defaultItem.rightBarButtonItem = rightDefaultButton;
5、其他重要属性
UINavgationBar的topItem指定了当前navgation bar显示的内容,topItem为栈顶元素,假如当前navgation bar维护了n个items,那么topItem的索引为n-1
UINavgationBar的backItem保存了topItem的下一个item,即索引为n-2的item。如果当前只有一个item,那么该属性为nil,而不是与topItem指向相同的item
- UINavigationBar
- UINavigationBar
- UINavigationBar
- UINavigationBar
- UINavigationBar
- UINavigationBar
- UINavigationBar
- UINavigationBar
- UINavigationBar
- UINavigationBar
- uinavigationbar
- UINavigationBar + UISegmentedControl
- UINavigationController,UINavigationBar
- UINavigationBar 贴图
- 定制UINavigationBar
- 自定义UINavigationBar
- 自定义UINavigationBar
- UINavigationBar.h
- 什么是POP3、SMTP和IMAP?
- hadoop 异常 reduce长时间卡住停滞不前的问题
- 网址收藏
- “见贤思齐”,多和厉害的人交流,才有大格局
- PPP完全理解(三)
- UINavigationBar
- 关于updatapanel和jquery之间的冲突 以及scriptmanager.registerstartupscript方法的重点
- 初探MITM-中间人攻击
- 修改clob字段并插入新表|转|
- 信号量 互斥锁 条件变量的区别
- 实现大象喝水(c语言)
- c# 扩展方法奇思妙用基础篇九:Expression 扩展
- JavaScriptday1
- 经营你的iOS应用日志(一):开始编写日志组件