OS UIButton之UIButtonType详解-转
我做了一个关于UIButtonType的Demo,效果如下图:
UIButtonType各个类型的解释:
typedef NS_ENUM(NSInteger, UIButtonType) {
UIButtonTypeCustom = 0,
UIButtonTypeSystem,
UIButtonTypeDetailDisclosure,
UIButtonTypeInfoLight,
UIButtonTypeInfoDark,
UIButtonTypeContactAdd,
UIButtonTypePlain,
UIButtonTypeRoundedRect = UIButtonTypeSystem
};
复制代码
UIButtonTypeCustom:
官方:No button style.
解释:自定义的按钮(无样式)UIButtonTypeSystem:
官方:A system style button, such as those shown in navigation bars and toolbars.
解释:系统样式UIButtonTypeDetailDisclosure:
官方: A detail disclosure button.
解释:细节详情样式UIButtonTypeInfoLight:
官方:An information button that has a light background.
解释:按钮图片为i字母(info)亮的信息类型UIButtonTypeInfoDark:
官方:An information button that has a dark background.
解释:按钮图片为i字母(info)暗的信息类型
注意: iOS7及之后,只有在设置showsTouchWhenHighlighted为YES的时候,DetailDisclosure的外观和InfoLight/InfoDark不同(测试的时候我并没有看出来什么不同,如果你看出来了,劳烦告诉我),其他情况下都相同
UIButtonTypeContactAdd:
官方:A contact add button.
解释:加号(➕)按钮类型UIButtonTypePlain:
官方:A standard system button without a blurred background view.
解释:没有模糊背景视图的标准的系统按钮 不过只支持 tvOSUIButtonTypeRoundedRect = UIButtonTypeSystem:
官方:A rounded-rectangle style button.
解释:方形的圆角形式的按钮,在iOS7后被废弃,现在需要使用border的方式来做到效果
注意:(UIButtonTypeRoundedRect已废弃, UIButtonTypeRoundedRect的枚举值为1 !
相关代码
#import "QiButton_ButtonTypeViewController.h"
@interface QiButton_ButtonTypeViewController ()
@end
@implementation QiButton_ButtonTypeViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"UIButtonType";
[self buttonType];
}
#pragma mark - Private functions
- (void)buttonType {
NSArray <NSString *>*buttonTypes = @[@"UIButtonTypeCustom",
@"UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0)",
@"UIButtonTypeDetailDisclosure",
@"UIButtonTypeInfoLight",
@"UIButtonTypeInfoDark",
@"UIButtonTypeContactAdd",
@"UIButtonTypePlain API_AVAILABLE(tvos(11.0)) API_UNAVAILABLE(ios, watchos)",
@"7 = UIButtonTypePlain | UIButtonTypeSystem",
@"UIButtonTypeRoundedRect = UIButtonTypeSystem",
@"new a Button"];
CGFloat btnHeight = [UIScreen mainScreen].bounds.size.height / buttonTypes.count;
for (NSInteger buttonTypeI = 0 ; buttonTypeI < buttonTypes.count; buttonTypeI ++) {
UIButton *buttonTypeBtn = [UIButton buttonWithType:buttonTypeI];
// 设置最后的一个按钮 new的方式创建
if (buttonTypeI == buttonTypes.count - 1) {
// 经测试 打印的btn.buttonType 为 UIButtonTypeCustom 观察button的显示样式也是如此
buttonTypeBtn = [UIButton new];
[buttonTypeBtn setImage:[UIImage imageNamed:@"smallQiShareLogo"] forState:UIControlStateNormal];
[buttonTypeBtn setImage:[UIImage imageNamed:@"smallQiShareLogo"] forState:UIControlStateHighlighted];
} else if(buttonTypeI == buttonTypes.count - 2) {
/** 注意UIButtonTypeRoundedRect = UIButtonTypeSystem 真正的值为 1 而不是7
如果以 [UIButton buttonWithType:7] 方式创建UIButton
相当于 [UIButton buttonWithType:UIButtonTypePlain | UIButtonTypeSystem];
*/
buttonTypeBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[buttonTypeBtn setImage:[UIImage imageNamed:@"smallQiShareLogo"] forState:UIControlStateNormal];
[buttonTypeBtn setImage:[UIImage imageNamed:@"smallQiShareLogo"] forState:UIControlStateHighlighted];
} else if(buttonTypeI == UIButtonTypeCustom || buttonTypeI == UIButtonTypeSystem || buttonTypeI == UIButtonTypeRoundedRect) {
[buttonTypeBtn setImage:[UIImage imageNamed:@"smallQiShareLogo"] forState:UIControlStateNormal];
[buttonTypeBtn setImage:[UIImage imageNamed:@"smallQiShareLogo"] forState:UIControlStateHighlighted];
} else if(buttonTypeI == UIButtonTypeDetailDisclosure || buttonTypeI == UIButtonTypeInfoLight || buttonTypeI == UIButtonTypeInfoDark) {
buttonTypeBtn.showsTouchWhenHighlighted = YES;
}
[self.view addSubview:buttonTypeBtn];
buttonTypeBtn.frame = CGRectMake(.0, buttonTypeI * btnHeight, CGRectGetWidth(self.view.frame), btnHeight);
buttonTypeBtn.backgroundColor = (buttonTypeI % 2 ? [UIColor lightGrayColor] : [UIColor colorWithWhite:0.8 alpha:0.8]);
[buttonTypeBtn setTitle:buttonTypes[buttonTypeI] forState:UIControlStateNormal];
buttonTypeBtn.titleLabel.numberOfLines = 0;
[buttonTypeBtn addTarget:self action:@selector(buttonTypeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
}
}
#pragma mark - Action functions
- (void)buttonTypeButtonClicked:(UIButton *)sender {
sender.selected = !sender.selected;
}
@end
作者:QiShare
OS UIButton之UIButtonType详解-转的更多相关文章
- 苹果电脑Mac OS系统重装图文详解
苹果电脑Mac OS系统重装图文详解 本文来自于[系统之家] www.xp85.com现在电脑都很强大,可是也很脆弱,常常需要你去维护,甚至经常需要你重装系统,那么Mac OS又如何重装系统呢?刚刚使 ...
- iOS:UIButton按钮的详解
UIButton的详细介绍: 一.按钮具有的属性: @property(nonatomic,readonly) UIButtonType buttonType; //按钮形状类型 @property ...
- python os.path模块常用方法详解:转:http://wangwei007.blog.51cto.com/68019/1104940
1.os.path.abspath(path) 返回path规范化的绝对路径. >>> os.path.abspath('test.csv') 'C:\\Python25\\test ...
- 【python基础】os.path模块常用方法详解
os.path模块 主要用于文件的属性获取,在编程中经常用到,以下是该模块的几种常用方法. 更多的方法可以去查看官方文档:http://docs.python.org/library/os.path. ...
- python os.path模块常用方法详解
os.path模块主要用于文件的属性获取,在编程中经常用到,以下是该模块的几种常用方法.更多的方法可以去查看官方文档:http://docs.python.org/library/os.path.ht ...
- python os.path模块常用方法详解(转)
转自:https://www.cnblogs.com/wuxie1989/p/5623435.html os.path模块主要用于文件的属性获取,在编程中经常用到,以下是该模块的几种常用方法.更多的方 ...
- python os.path模块常用方法详解 ZZ
os.path模块主要用于文件的属性获取,在编程中经常用到,以下是该模块的几种常用方法.更多的方法可以去查看官方文档:http://docs.python.org/library/os.path.ht ...
- python os.path模块用法详解
abspath 返回一个目录的绝对路径 Return an absolute path. >>> os.path.abspath("/etc/sysconfig/selin ...
- MAC OS 命令行使用详解【转】
你可以整天驾驶汽车而不用知道如何修理它们,但是如果你希望当一个维护员,你就需要知道事情是如何运作的.同样的事情也发生在了 Mac OS X 上:你可以一直使用 Mac 而不用知道如何修理它,但是如果你 ...
随机推荐
- spring4.x企业应用开发读书笔记1
第一章 概述 1 spring 以 ioc 和 aop 为内核,提供了展现层 springMVC.持久层SpringJDBC及业务层事务管理等一站式企业级应用技术. 2spring的特性 方便解耦,简 ...
- 如何开发一个npm包并发布到npm中央仓库
转自: https://liaolongdong.com/2019/01/24/publish-public-npm.html 如何开发一个npm包并发布到npm中央仓库需求背景:平时在项目工作中可能 ...
- Hive Authorization
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Authorization https://www.cloudera.c ...
- servlet 标红的错误笔记
错误原因,没有添加来自Tomcat服务器的jar包依赖. 解决方法
- Oracle spatial空间查询的选择度分析
在上一篇中,我用一个案例演示了对于数值或字符串类型的字段,选择度的计算方法.并证明了当字段值的选择度不同时,将会影响CBO选择最终的执行计划.对于可排序的字段类型,选择度计算模型已经有很多人写博客介绍 ...
- Jenkins+TestNG+gitlab+maven持续集成
准备工作: 1.安装Jenkins 网上有jenkins安装配置教程 2.jenkins配置 2.1全局工具配置 配置JDK JDK别名:名称可以随意,但是要方便识别 JAVA_HOME:centos ...
- IP通信学习心得01
一.物理拓扑 1. 1) 总线拓扑 特点:所有设备都处于同一个冲突域与广播域,共享相同的带宽 一次只能有一个设备传输,且两端要安装端接器. 传输介质:同轴电缆.(注:10Base5:容量10M 传输5 ...
- 从GitLab上创建分支本地拉取项目和提交项目详解
很多公司前端项目都是部署在GitLab上的,今天我要分享的就是如何从GitLab上创建新的分支并在本地拉取和提交项目 一.在GitLab上面创建自己新的分支 首先你得注册一个账号,登陆之后进入项目Pr ...
- Linux中的13个基本Cat命令示例
cat(“ concatenate ”的缩写)命令是Linux / Unix等操作系统中最常用的命令之一.cat命令允许我们创建单个或多个文件,查看文件包含,连接文件以及在终端或文件中重定向输出.在本 ...
- 01-打印Hello World、变量
一.打印Hello World 下面就是我们写的打印hello world程序 在go语言中://代表单行注释,/**/代表多行注释 //单行注释 /* 多行注释 多行注释 */ package ma ...