我做了一个关于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.
    解释:没有模糊背景视图的标准的系统按钮 不过只支持 tvOS

  • UIButtonTypeRoundedRect = 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详解-转的更多相关文章

  1. 苹果电脑Mac OS系统重装图文详解

    苹果电脑Mac OS系统重装图文详解 本文来自于[系统之家] www.xp85.com现在电脑都很强大,可是也很脆弱,常常需要你去维护,甚至经常需要你重装系统,那么Mac OS又如何重装系统呢?刚刚使 ...

  2. iOS:UIButton按钮的详解

    UIButton的详细介绍: 一.按钮具有的属性: @property(nonatomic,readonly) UIButtonType buttonType;  //按钮形状类型 @property ...

  3. python os.path模块常用方法详解:转:http://wangwei007.blog.51cto.com/68019/1104940

    1.os.path.abspath(path) 返回path规范化的绝对路径. >>> os.path.abspath('test.csv') 'C:\\Python25\\test ...

  4. 【python基础】os.path模块常用方法详解

    os.path模块 主要用于文件的属性获取,在编程中经常用到,以下是该模块的几种常用方法. 更多的方法可以去查看官方文档:http://docs.python.org/library/os.path. ...

  5. python os.path模块常用方法详解

    os.path模块主要用于文件的属性获取,在编程中经常用到,以下是该模块的几种常用方法.更多的方法可以去查看官方文档:http://docs.python.org/library/os.path.ht ...

  6. python os.path模块常用方法详解(转)

    转自:https://www.cnblogs.com/wuxie1989/p/5623435.html os.path模块主要用于文件的属性获取,在编程中经常用到,以下是该模块的几种常用方法.更多的方 ...

  7. python os.path模块常用方法详解 ZZ

    os.path模块主要用于文件的属性获取,在编程中经常用到,以下是该模块的几种常用方法.更多的方法可以去查看官方文档:http://docs.python.org/library/os.path.ht ...

  8. python os.path模块用法详解

    abspath 返回一个目录的绝对路径 Return an absolute path. >>> os.path.abspath("/etc/sysconfig/selin ...

  9. MAC OS 命令行使用详解【转】

    你可以整天驾驶汽车而不用知道如何修理它们,但是如果你希望当一个维护员,你就需要知道事情是如何运作的.同样的事情也发生在了 Mac OS X 上:你可以一直使用 Mac 而不用知道如何修理它,但是如果你 ...

随机推荐

  1. patch的用法【转】

    什么是patch patch即补丁之意,记录文件中的不同,能够与文件进行整合,从而改变文件中的内容 如何制作patch 在Linux系统中提供了diff程序,可以使用diff程序,比较文件之间的不同从 ...

  2. ThreadLocal:的面试

    ThreadLocal: 为解决多线程程序的并发问题提供了一种新的思路.使用这个工具类可以很简洁地编写出优美的多线程程序. 当使用ThreadLocal维护变量时,ThreadLocal为每个使用该变 ...

  3. 搭建高可用rabbitmq集群及spring boot实现集群配置

    java spring boot配置: //具体参看了配置的源码 org.springframework.boot.autoconfigure.amqp.RabbitProperties //Rabb ...

  4. windows 安装 mysql 启动

    mysqld --defaults-file="d:/lovejava/mysql-5.6/my-default.ini"

  5. linux系统上传下载命令rz和sz的教程

    (一)安装方法汇总(注意:一下命令如果没有权限的需要在每个命令前面加一个sudo) 1.安装方法(推荐) sudo yum install lrzsz 2.在安装Linux系统时选中“DialupNe ...

  6. Oracle11g R2客户端安装图文详解过程

    转: Oracle11g R2客户端安装图文详解过程 2018-06-17 13:30:26 大话JAVA的那些事 阅读数 4129更多 分类专栏: Oracle   版权声明:本文为博主原创文章,遵 ...

  7. 基于ifc数据的bim模型吊装模拟-1

    基于ifc数据的bim模型吊装模拟-1 IfcWallStandardCase    IfcColumn

  8. Docker CentOS / Ubuntu容器开启 SSH 服务

    Docker CentOS / Ubuntu容器开启 SSH 服务 在CentOS容器内执行 yum install passwd openssl openssh-server -y # Ubuntu ...

  9. ios开发 需要注意的地方、注意事项

    /* 一.LaunchScreenLaunchScreen产生原因:代替之前的启动图片好处:1.可以展示更多的东西2.可以只需要出一个尺寸的图片. 启动图片的优先级启动图片 < LaunchSc ...

  10. Python - Django - form 组件内置的正则校验器

    app01/models.py: from django.db import models class UserInfo(models.Model): username = models.CharFi ...