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 的使用效率,进而提供 ...
随机推荐
- 利用Express和ejs编写简单页面
1.创建临时文件夹ejsdemo $ mkdir ejsdemo 2.进入ejsdemo 初始化项目 $ npm init 3.安装express $ npm install express --sa ...
- MySQL数据类型DECIMAL用法
MySQL DECIMAL数据类型用于在数据库中存储精确的数值.我们经常将DECIMAL数据类型用于保留准确精确度的列,例如会计系统中的货币数据. 要定义数据类型为DECIMAL的列,请使用以下语法: ...
- 216. Combination Sum III(medium, backtrack, 本类问题做的最快的一次)
Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...
- Java 程序运行过程中的内存分析
作为 java 程序员,都应该知道 Java 程序运行在 JVM(Java Virtual Machine,Java 虚拟机)上,可以把 JVM 理解成 Java 程序和操作系统之间的桥梁,JVM 实 ...
- 【移动开发】targetSdkVersion的作用
在AndroidMenifest.xml中,常常会有下面的语句: <uses-sdk android:minSdkVersion="4" android:targetSdkV ...
- npm killed有可能是内存不够, 为Ubuntu增加swap
参考 http://www.cnblogs.com/owenyang/p/4282283.html 查看swap使用策略 cat /proc/sys/vm/swappiness 0代表尽量使用物理内存 ...
- Android Multimedia框架总结(二十二)MediaCodec中C++中创建到start过程及状态变换
上一章介绍MediaCodec中创建到start过程(到jni部分),从今天开始,将深入源码中看看其c++过程,看下Agenda如下: mediacodec.h CreateByType initMe ...
- Unity UGUI图文混排(七) -- 下划线
之前更新超链接的时候,忘了搭配实现一个下划线的功能,这篇文章就是来补上这一个功能,时间有点长,一方面没有很好的思路,一方面也没多少时间. 先在网上收集了一下下划线的实现操作,一种是在文本下再创建一个文 ...
- [openresty]安装nginx_lua
这种方式是直接安装openresty ,不是通过重新编译nginx Ubuntu 安装 安装依赖包 $ sudo apt-get install libreadline-dev libncurses5 ...
- windows系统下安装和使用ROS的解决方案 (1 win_ros 2 rosserial_windows)
具体请参考官网: 1 http://wiki.ros.org/win_ros 2 https://github.com/ros-windows/win_ros 3 http://wiki.ros ...