iOS中 UIToolBar 技术分享
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 技术分享的更多相关文章
- iOS中 UIProgressView 技术分享
UIProgressView 继承自UIView,用来显示进度的,如音乐,视频的缓冲进度,文件的上传下载进度等.让用户知道当前操作完成了多少,离操作结束还有多远 AppDelegate.m Progr ...
- ios外包公司——技术分享:手机应用开发步骤
1. 确定你的创意 您的创意是否有人做过,如果有类似的app,那就要多多考虑,争取超越并且有一些独特的优化设计在其中 2. 定位应用 通过苹果的人机界面指南(Human Interface Guide ...
- ios外包公司——技术分享:IOS开发教程
iOS入门培训,适合已经有C/C++/Java/C#基础的人学习. 本大仙主讲,总共4讲(第4讲尚在制作中),这仅仅是iOS开发的入门而已.学完本教程,应该已经足够你自学并开发app了. ...
- iOS中常用技术链接
1.弹幕技术 http://www.jianshu.com/p/f39b8abc8008 2.通过CAGradientLayer制作渐变色效果 http://blog.it985.com/7986.h ...
- fir.im Weekly - 8 个不能错过的 iOS / Android 技术分享
本期 fir.im Weekly 收集了 2 月下旬新鲜出炉的 iOS /Android 技术分享.源码等,iOS 中图片技术的解压缩.逆向实战.iOS SDK 实践,Android架构思考.Andr ...
- UWA 技术分享连载 转载
技术分享连载1 Q1:Texture占用内存总是双倍,这个是我们自己的问题,还是Unity引擎的机制? Q2:我现在发现两个因素直接影响Overhead,一个是Shader的复杂度,一个是空Updat ...
- iOS开发技术分享(1)— iOS本地数据存储
iOS开发技术分享(1)— iOS本地数据存储 前言: 我本是一名asp.net程序员,后来加入了iOS游戏开发队伍,到现在也有一年多的时间了.这一年来,每天都干到2.3点钟才睡觉,不为别的,只为了学 ...
- 【腾讯Bugly干货分享】iOS 中 HTTPS 证书验证浅析
本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:https://mp.weixin.qq.com/s/-fLLTtip509K6pNOTkflPQ 导语 本 ...
- OS X 和iOS 中的多线程技术(上)
OS X 和iOS 中的多线程技术(上) 本文梳理了OS X 和iOS 系统中提供的多线程技术.并且对这些技术的使用给出了一些实用的建议. 多线程的目的:通过并发执行提高 CPU 的使用效率,进而提供 ...
随机推荐
- Servlet生命周期与工作原理(转载)
Servlet生命周期分为三个阶段: 1,初始化阶段 调用init()方法 2,响应客户请求阶段 调用service()方法 3,终止阶段 调用destroy()方法 Servlet初始化阶段: 在 ...
- Mobx使用详解
Mobx是一个功能强大,上手非常容易的状态管理工具.就连redux的作者也曾经向大家推荐过它,在不少情况下你的确可以使用Mobx来替代掉redux. 本教程旨在介绍其用法及概念,并重点介绍其与Reac ...
- day07 Cookie 和 Session(非常重要)
day07 Cookie 和 Session 1. 会话技术 2. cookie 的方法和 cookie 案例-显示用户上次访问网站的时间 3. cookie 的细节 - 删除 cookie 4. S ...
- Node.js 子进程
稳定性: 3 - 稳定 Node 通过 child_process 模块提供了 popen(3) 数据流. 它能在非阻塞的方式中,通过 stdin, stdout, 和 stderr 传递数据. (请 ...
- docker环境 mysql读写分离 mycat maxscale
#mysql读写分离测试 环境centos 7.4 ,docker 17.12 ,docker-compose mysql 5.7 主从 mycat 1.6 读写分离 maxscale 2.2.4 读 ...
- springMVC源码解析--HandlerMethodArgumentResolverComposite参数解析器集合(二)
上一篇博客springMVC源码分析--HandlerMethodArgumentResolver参数解析器(一)中我们已经介绍了参数解析相关的东西,并且也提到了HandlerMethodArgume ...
- IP_ADD_MEMBERSHIP 失败
/*将本机加入多播组*/ err = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,&mreq, sizeof(mreq)); if (err &l ...
- Programming In Scala笔记-第十九章、类型参数,协变逆变,上界下界
本章主要讲Scala中的类型参数化.本章主要分成三个部分,第一部分实现一个函数式队列的数据结构,第二部分实现该结构的内部细节,最后一个部分解释其中的关键知识点.接下来的实例中将该函数式队列命名为Que ...
- iOS 应用打包命令一览
文章转载自:http://www.jianshu.com/p/5d59966eaecc 文章排版部分根据自己的理解做了一些修改. 各种命令的简介 使用命令打包iOS 应用一般会用到 xcodebuli ...
- Ubuntu使用dpkg安装软件依赖问题解决 ubuntu-tweak ubuntu 16.04 LTS 系统清理
Ubuntu使用dpkg安装软件依赖问题解决 这里以在ubuntu 16.04安装Ubuntu Tweak为例进行说明,通常安装包依赖问题都可以用这种方法解决: sudo apt-get instal ...