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 的使用效率,进而提供 ...
随机推荐
- angularJS入门笔记
1.debug调试工具:batarang2.ng指令 1.ng-app=" " 定义angularJS的使用范围:----main方法,入口 ng-app="myModu ...
- 48. Rotate Image(中等)
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- MYSQL 表左连接 ON AND 和ON WHERE 的区别
首先是针对左右连接,这里与inner join区分 在使用left join时,on and 和on where会有区别 1. on的条件是在连接生成临时表时使用的条件,以左表为基准 ,不管on中的条 ...
- Mysql数据库连接报错!1130:host XXX is not allowed to connect to this mysql server
我猜想是可能是连接的用户权限问题.结果这样子操作mysql库,可以解决此问题.在本机登入mysql后,更改 “mysql” 数据库里的 “user” 表里的 “host” 项,从”localhost” ...
- EF Core 2.0使用MsSql/Mysql实现DB First和Code First
参考地址 EF官网 ASP.NET Core MVC 和 EF Core - 教程系列 环境 Visual Studio 2017 最新版本的.NET Core 2.0 SDK 最新版本的 Windo ...
- sourceTree+gerrit管理代码
第一次接触gerrit,会对这种代码管理方式非常排斥,尤其是习惯了用sourceTree配合git进行代码管理的同学.不爽归不爽,代码还得写,我们的目标是让开发过程爽起来. 关于gerrit的知识,移 ...
- Unity CommandBuffer的一些学习整理
1.前言 近期在整理CommandBuffer这块资料,之前的了解一直较为混乱. 算不上新东西了,但个人觉得有些时候要比加一个摄像机再转RT廉价一些,至少省了深度排序这些操作. 本文使用两个例子讲解C ...
- Oracle12c中SQL性能优化(SQL TUNING)新特性之自动重优化(automatic reoptimization)
Oracle12c中的自动重优化 Oracle12c中的自适应查询优化有一系列不同特点组成.像自适应计划(AdaptivePlans)功能可以在运行时修改执行计划,但并不允许计划中连接顺序的改变.自动 ...
- xshell连接centos与ubuntu
操作系统:Windows 7 应用软件:Ware Workstation &Xshell 5 Linux:CentOS 7 Minimal &Ubuntu Server 16 ==== ...
- 初识Spark2.0之Spark SQL
内存计算平台spark在今年6月份的时候正式发布了spark2.0,相比上一版本的spark1.6版本,在内存优化,数据组织,流计算等方面都做出了较大的改变,同时更加注重基于DataFrame数据组织 ...