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. sea.js及三种加载方式的异同

      一.前言     浏览器本身并不提供模块管理的机制,过去网页开发中,为了使用各种模块,不得不在加入一大堆script标签.这样就使得网页体积臃肿,难以维护,还产生大量的HTTP请求,拖慢显示速度, ...

  2. python学习之路网络编程篇(第四篇)- 续

    Memcache简介 Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速 ...

  3. Numpy函数学习--genfromtxt函数

    genfromtxt函数 今天学习时遇到了genfromtxt函数 world_alcohol = numpy.genfromtxt("world_alcohol.txt",del ...

  4. JDBC访问数据库的一些小技巧

    一. 连接 1.使用try with resources关闭JDBC资源 示例代码如下: public List<User> getUser(int userId) { try (Conn ...

  5. android NDK的下载-文件太大

    需要FQ,建议使用VPN,下载前准备点时间配置网络环境.我的百度网盘好像有~~不过忘记地址了,改天共享,或者私聊我. 2015.4 Android 5.1 Android Studio https:/ ...

  6. 自定义View总结2

    自定义控件: 1.组合控件:将系统原生控件组合起来,加上动画效果,形成一种特殊的UI效果 2.纯粹自定义控件:继承自系统的View,自己去实现view效果 优酷菜单: 1.系统原生的旋转和位置动画并没 ...

  7. 字符编码(ASCII、ANSI、GB2312、UTF-8等)系统梳理

    引言 在显示器上看见的文字.图片等信息在电脑里面其实并不是我们看见的样子,即使你知道所有信息都存储在硬盘里,把它拆开也看不见里面有任何东西,只有些盘片.假设,你用显微镜把盘片放大,会看见盘片表面凹凸不 ...

  8. 在ubuntu上部署一个samba服务器

    今天公司装了一天新电脑,准备把它装成服务器,于是为了方便开发的使用,我在上面部署了一个samba,用来实现window和linux的联系: 具体步骤,我详细的查看了百度,高手云集,以下就是总结了网友的 ...

  9. Java中读取Excel功能实现_POI

    这里使用apache的poi进行读取excel 1,新建javaproject 项目:TestExcel 2,导入包 包下载地址:http://poi.apache.org/download.html ...

  10. Java进阶(三十九)Java集合类的排序,查找,替换操作

    Java进阶(三十九)Java集合类的排序,查找,替换操作 前言 在Java方向校招过程中,经常会遇到将输入转换为数组的情况,而我们通常使用ArrayList来表示动态数组.获取到ArrayList对 ...