navigation bar 分为三个部分,左按钮,右按钮和中间的View.

在Controller中可以通过以三个方式来引用:

  • self.navigationItem.titleView
  • self.navigationItem.leftBarButtonItem
  • self.navigationItem.rightBarButtonItem
左右按钮可以使用UIBarButtonItem来构造. 他默认有很多种按钮可攻选择:
Java代码 
  1. typedef enum {
  2. UIBarButtonSystemItemDone,
  3. UIBarButtonSystemItemCancel,
  4. UIBarButtonSystemItemEdit,
  5. UIBarButtonSystemItemSave,
  6. UIBarButtonSystemItemAdd,
  7. UIBarButtonSystemItemFlexibleSpace,
  8. UIBarButtonSystemItemFixedSpace,
  9. UIBarButtonSystemItemCompose,
  10. UIBarButtonSystemItemReply,
  11. UIBarButtonSystemItemAction,
  12. UIBarButtonSystemItemOrganize,
  13. UIBarButtonSystemItemBookmarks,
  14. UIBarButtonSystemItemSearch,
  15. UIBarButtonSystemItemRefresh,
  16. UIBarButtonSystemItemStop,
  17. UIBarButtonSystemItemCamera,
  18. UIBarButtonSystemItemTrash,
  19. UIBarButtonSystemItemPlay,
  20. UIBarButtonSystemItemPause,
  21. UIBarButtonSystemItemRewind,
  22. UIBarButtonSystemItemFastForward,
  23. UIBarButtonSystemItemUndo,      // available in iPhone 3.0
  24. UIBarButtonSystemItemRedo,      // available in iPhone 3.0
  25. } UIBarButtonSystemItem;
通过构造初始化可以设置这些按钮的种类:
Java代码 
  1. [[[UIBarButtonItem alloc]
  2. initWithBarButtonSystemItem:UIBarButtonSystemItemPlay
  3. target:nil action:NULL] autorelease];
除此之外,UIBarButtonItem还有几种外观风格:
Java代码 
  1. typedef enum {
  2. UIBarButtonItemStylePlain,    // shows glow when pressed
  3. UIBarButtonItemStyleBordered,
  4. UIBarButtonItemStyleDone,
  5. } UIBarButtonItemStyle;
当然按钮有风格之分, navigation bar 也有几种可选风格:
Java代码 
  1. typedef enum {
  2. UIBarStyleDefault          = 0,
  3. UIBarStyleBlack            = 1,
  4. UIBarStyleBlackOpaque      = 1, // Deprecated. Use UIBarStyleBlack
  5. UIBarStyleBlackTranslucent = 2, // Deprecated. Use UIBarStyleBlack and set the translucent property to YES
  6. } UIBarStyle;
通过:navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent这样的语句就可以设置了.
这个UIBarStyle的风格还适用于UIToolbar. 并且UIToolBar中也是可以放置UIBarButtonItem的.
Java代码 
  1. NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:4];
  2. UIBarButtonItem *flexibleSpaceItem;
  3. flexibleSpaceItem = [[[UIBarButtonItem alloc]
  4. initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
  5. target:nil action:NULL] autorelease];
  6. [buttons addObject:flexibleSpaceItem];
  7. [flexibleSpaceItem release];
  8. UIBarButtonItem *item;
  9. item = [[UIBarButtonItem alloc]
  10. initWithImage:[UIImage imageNamed:@"down.png"]
  11. style:UIBarButtonItemStylePlain
  12. target:self
  13. action:@selector(decrement:)];
  14. [buttons addObject:item];
  15. [item release];
  16. item = [[UIBarButtonItem alloc]
  17. initWithImage:[UIImage imageNamed:@"up.png"]
  18. style:UIBarButtonItemStylePlain target:self
  19. action:@selector(increment:)];
  20. [buttons addObject:item];
  21. [item release];
  22. item = [[[UIBarButtonItem alloc]
  23. initWithBarButtonSystemItem:UIBarButtonSystemItemPlay
  24. target:nil action:NULL] autorelease];
  25. [buttons addObject:item];
  26. [item release];
  27. flexibleSpaceItem = [[[UIBarButtonItem alloc]
  28. initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
  29. target:nil action:NULL] autorelease];
  30. [buttons addObject:flexibleSpaceItem];
  31. [flexibleSpaceItem release];
  32. UIToolbar *toolbar = [[UIToolbar alloc] init];
  33. toolbar.barStyle = UIBarStyleBlackOpaque;
  34. [toolbar setItems:buttons animated:YES];
  35. [toolbar sizeToFit];

转载于:https://www.cnblogs.com/KiloNet/archive/2010/08/24/1807328.html

iPhone NavigationBar和UIToolbar基础相关推荐

  1. 疯狂iOS 讲义(上) Objective-C 2.0与iPhone/iPad应用开发基础(国内首部iOS 7相关著作,小伙伴们,学好iPhone/iPad应用开发,我们一起做土豪吧)

    疯狂iOS 讲义(上) Objective-C 2.0与iPhone/iPad应用开发基础(国内首部iOS 7相关著作,小伙伴们,学好iPhone/iPad应用开发,我们一起做土豪吧) 李刚 编 IS ...

  2. 疯狂iOS 讲义(上) Objective-C 2.0与iPhone/iPad应用开发基础

    疯狂iOS 讲义(上)Objective-C 2.0与iPhone/iPad应用开发基础(国内首部iOS 7相关著作,小伙伴们,学好iPhone/iPad应用开发,我们一起做土豪吧) 李刚编 ISBN ...

  3. iPhone开发教程 UI基础课程(58课时)

    qianqianlianmeng iPhone开发教程 UI基础课程(58课时) 第一章   iPhone开发入门 UI基础课程 第一章 iPhone开发入门 1.1 iOS概述和架构         ...

  4. 吃鸡神器iPhone苹果7Plus手机基础使用教程

    吃鸡神器iPhone苹果7Plus手机基础使用教程 #和平精英#吃鸡神器 #数码家电 觉得行的压个AK给我看看,@我 轻喷 吃鸡神器iPhone苹果7Plus手机基础使用教程

  5. iPhone手机的这些基础功能 你都知道吗?

    iOS作为独立的手机操作系统,不仅异于各类深度定制的安卓系统,即便与原生的安卓相比,在一些功能与体验上也有蛮大的区别! 功能一:浏览器长截图 iPhone自带的Safari浏览器可以长截图,同时按住& ...

  6. IOS 学习笔记 Toolbar NavigationBar 导航栏 工具栏

    Toolbar使用gif图展示效果图: NavigationBar使用gif效果图 导航栏和工具栏(UIToolbar and NavigationBar) 工具栏和导航栏实际上是有很大差距的,这里放 ...

  7. 苹果正在研发iPhone检测抑郁症功能

    近日,据国外媒体报道,知情人士透露,苹果公司正在与加州大学洛杉矶分校和制药公司百健公司合作,开发能够帮助诊断抑郁症和认知能力下降的iPhone功能. 据悉,研究人员希望通过对数据的分析,比如行动能力. ...

  8. iPhone又降价了!京东、苏宁安排上了 iPhone XS系列最高直降1700元

    为了促进产品销量以及回馈用户,京东方面宣布对部分Apple产品开启促销活动.其中,针对iPhone XS及iPhone XS Max进行价格调整:iPhone XS Max官网价最高直降1700元,i ...

  9. iPhone开发视频教程 Objective-C部分 (51课时)

    第一.二章  OC基础语法 iPhone开发教程 第一章 OC基础语法  iPhone开发概述-必看(1.1) http://www.apkbus.com/android-102215-1-1.htm ...

最新文章

  1. Docker最全教程——从理论到实战(六)
  2. JQuery 模糊匹配
  3. linux正则表达式awk讲解
  4. 5.1 上网本安装安卓x86_生信工具 | antiSMASH 安装教程
  5. redis的bigkeys命令之原理
  6. 正則表達式,终极使用!3个工具,搞定一切
  7. POS打印机系列之 = 并口
  8. python -day16-模块介绍
  9. 分区字段必须包含在主键字段_十年Java开发经验分享:24 个必须掌握的数据库面试问题...
  10. Django signal
  11. window10运行python弹出商店_Python上架Windows 10应用商店,但主要用于学习,正式项目还...
  12. 软件测试中动态测试与静态测试的区别
  13. 红包码收款码合二为一
  14. 第三章 分布式扩展(一)
  15. C++偶遇-菱形继承
  16. 苹果手表支持心电图功能,可能还是逃不过噱头的命运
  17. Docker commit 联系
  18. 网络层协议介绍与概述
  19. 出现数据库不给访问的情况
  20. geoserver发布TIF格式瓦片地图

热门文章

  1. Java字符串equals()
  2. readline_Swift readLine(),Swift print()
  3. 浅析人工智能自然语言生成定义
  4. 《混合云计算》——2.3 整合势在必行
  5. cpu out of order, 性能优化
  6. 在Sublime Text 2下面开发Sass
  7. python plot linestyle 线型颜色及线条控制(linestyle、marker、color)
  8. Ubuntu16.04 安装LaTex并配置中文环境
  9. Percona XtraBackup
  10. Indent Guides插件格式代码