UIToolBar存在于UINavigationController导航栏控制器中,而且默认被隐藏。当设置UIToolBar显示,或者存在UITabBarController且tabbar被隐藏的时候,toolbar就会显示出来。我们使用UIToolBar是由于它一直显示在屏幕底部,有时候我们需要在屏幕底部添加按钮或提示信息,就不需要另外创建一个UIView或其他视图了。因为创建UIView或其他视图需要适应屏幕尺寸,也会隐藏掉底部的视图显示,造成显示不完整的情况等。

fixbleSpace类型的BarButtonItem  主要用于工具条钮间距的调整.UIBarButtonSystemItem提供了一系列的系统按钮,其中有两个UIBarButtonSystemItemFlexibleSpace和UIBarButtonSystemItemFixedSpace

这俩不是按钮,而是调整按钮间距用的对象

AppDelegate.m

 self.window.rootViewController = [[[UINavigationController alloc]initWithRootViewController:[RootViewController new]]autorelease];

/************************** UIToolBar *************************************/

//设置navigationController的toolbar为不隐藏
    self.navigationController.toolbarHidden = NO;
    //设置navigationController的toolbar的背景颜色
    self.navigationController.toolbar.barTintColor = [UIColor orangeColor];

    //下面生成3中常用的UIBarButtonItem 分别为:
    //1. 系统提供的UIBarButtonItem类型
    UIBarButtonItem * item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(cameraClick:)];

    //2. 自定义显示内容的UIBarButtonItem类型
    UIBarButtonItem * item2 = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(collectClick:)];

    UIImage * image = [[UIImage imageNamed:@"pause"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    //3.自定义图片的UIBarButtonItem类型
    UIBarButtonItem * item3 = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleDone target:self action:@selector(imageClick:)];

    //创建一个数组
    NSArray * ary = [NSArray arrayWithObjects:item1, item2, item3, nil];

    //将数组中的内容传递给navigationController的toolbarItems属性
    self.toolbarItems = ary;

/********************* fixbleSpace类型的BarButtonItem **********************/

UIBarButtonItem * item4 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];

    UIBarButtonItem * item5 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:nil action:nil];

    UIBarButtonItem * item6 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:nil action:nil];

    UIBarButtonItem * item7 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:nil action:nil];

//    不写默认靠左侧显示
    //    NSArray * ary = [[NSArray alloc] initWithObjects: item4, item5, item6, item7,  nil];

    //自动调间距
    NSArray * ary = [[NSArray alloc] initWithObjects: item4, self.flexibleSpace, item5, self.flexibleSpace, item6, self.flexibleSpace, item7, nil];

    //靠左侧显示
    //    NSArray * ary = [[NSArray alloc] initWithObjects: item4, item5, item6, item7, self.flexibleSpace, nil];

    //靠右侧显示
    //    NSArray * ary = [[NSArray alloc] initWithObjects: self.flexibleSpace, item4, item5, item6, item7, nil];

    self.toolbarItems = ary;

方法实现部分:

- (void)cameraClick:(UIBarButtonItem *)sender
{
    NSLog(@"第一个被点击");
}

- (void)collectClick:(UIBarButtonItem *)sender
{
    NSLog(@"第二个被点击");
}

- (void)imageClick:(UIBarButtonItem *)sender
{
    NSLog(@"第三个被点击");
}

iOS中 UIToolBar 技术分享的更多相关文章

  1. iOS中 UIProgressView 技术分享

    UIProgressView 继承自UIView,用来显示进度的,如音乐,视频的缓冲进度,文件的上传下载进度等.让用户知道当前操作完成了多少,离操作结束还有多远 AppDelegate.m Progr ...

  2. ios外包公司——技术分享:手机应用开发步骤

    1. 确定你的创意 您的创意是否有人做过,如果有类似的app,那就要多多考虑,争取超越并且有一些独特的优化设计在其中 2. 定位应用 通过苹果的人机界面指南(Human Interface Guide ...

  3. ios外包公司——技术分享:IOS开发教程

        iOS入门培训,适合已经有C/C++/Java/C#基础的人学习.   本大仙主讲,总共4讲(第4讲尚在制作中),这仅仅是iOS开发的入门而已.学完本教程,应该已经足够你自学并开发app了. ...

  4. iOS中常用技术链接

    1.弹幕技术 http://www.jianshu.com/p/f39b8abc8008 2.通过CAGradientLayer制作渐变色效果 http://blog.it985.com/7986.h ...

  5. fir.im Weekly - 8 个不能错过的 iOS / Android 技术分享

    本期 fir.im Weekly 收集了 2 月下旬新鲜出炉的 iOS /Android 技术分享.源码等,iOS 中图片技术的解压缩.逆向实战.iOS SDK 实践,Android架构思考.Andr ...

  6. UWA 技术分享连载 转载

    技术分享连载1 Q1:Texture占用内存总是双倍,这个是我们自己的问题,还是Unity引擎的机制? Q2:我现在发现两个因素直接影响Overhead,一个是Shader的复杂度,一个是空Updat ...

  7. iOS开发技术分享(1)— iOS本地数据存储

    iOS开发技术分享(1)— iOS本地数据存储 前言: 我本是一名asp.net程序员,后来加入了iOS游戏开发队伍,到现在也有一年多的时间了.这一年来,每天都干到2.3点钟才睡觉,不为别的,只为了学 ...

  8. 【腾讯Bugly干货分享】iOS 中 HTTPS 证书验证浅析

    本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:https://mp.weixin.qq.com/s/-fLLTtip509K6pNOTkflPQ 导语 本 ...

  9. OS X 和iOS 中的多线程技术(上)

    OS X 和iOS 中的多线程技术(上) 本文梳理了OS X 和iOS 系统中提供的多线程技术.并且对这些技术的使用给出了一些实用的建议. 多线程的目的:通过并发执行提高 CPU 的使用效率,进而提供 ...

随机推荐

  1. SUSE10的虚拟机安装以及ORACLE 11g的安装

    SUSE10虚拟机安装与ORACLE安装 作者:张欣橙 本文所需要的所有参数均位于文末附录中 一.SUSE10虚拟机的安装与创建 新建虚拟机安装 选择下一步 选择下一步 选择下一步 选择下一步 选择下 ...

  2. C#判断画的图形是不是三角形

    这个源代码写的不是十全十美,只是提供一个 还待完善的地方例如判断是否这个图形是封闭的.得空在解决吧 这只是一个算法上 谁有c#的参考手册网盘分享一份 谢谢 下面请看源码 凑够150个字了,不废话了. ...

  3. java里String类为何被设计为final

    前些天面试遇到一个非常难的关于String的问题,"String为何被设计为不可变的"?类似的问题也有"String为何被设计为final?"个人认为还是前面一 ...

  4. file的基本操作;file的修改

    file的基本操作 # Author:nadech # 文件读写/修改/ #data = open("yesterday",encoding="utf-8"). ...

  5. ng-book札记——内置指令

    Angular提供了一些内置指令(directive),这些添加在HTML元素(element)上的特性(attribute)可以赋予更多的动态行为. NgIf ngIf指令用于在某个条件下显示或者隐 ...

  6. Hibernate异常之命名查询节点未找到

    异常信息: java.lang.IllegalArgumentException: No query defined for that name [salaryEmps] at org.hiberna ...

  7. Python pandas.io.data 模块迁移

    这段时间用pandas做数据分析, import pandas.io.data as web 然后得到下面的错误提示 "The pandas.io.data module is moved ...

  8. Android 5.0新控件——FloatingActionButton(悬浮按钮)

    Android 5.0新控件--FloatingActionButton(悬浮按钮) FloatingActionButton是5.0以后的新控件,一个悬浮按钮,之所以叫做悬浮按钮,主要是因为自带阴影 ...

  9. iOS遍历数组的同时删除元素

    我们在遍历可变数组时,最好不要做删除数组中元素的操作. 因为删除操作可能会引起数组容量的变化,导致数组越界等问题. 以前在使用for循环遍历的时候遇到过这个问题. 当时的做法是使用enumerateO ...

  10. Ubuntu LTS 系统学习使用体会和实用工具软件汇总 6.04 8.04 10.04 12.04 14.04 16.04

    Ubuntu LTS 系统学习体会和工具软件汇总 6.04 8.04 10.04 12.04 14.04 16.04 ubuntu入门必备pdf:http://download.csdn.net/de ...