我做了一个关于UIButtonType的Demo,效果如下图:

UIButtonType各个类型的解释:

  1. typedef NS_ENUM(NSInteger, UIButtonType) {
  2. UIButtonTypeCustom = 0,
  3. UIButtonTypeSystem,
  4. UIButtonTypeDetailDisclosure,
  5. UIButtonTypeInfoLight,
  6. UIButtonTypeInfoDark,
  7. UIButtonTypeContactAdd,
  8. UIButtonTypePlain,
  9. UIButtonTypeRoundedRect = UIButtonTypeSystem
  10. };
  11. 复制代码
  • 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 !

相关代码


  1. #import "QiButton_ButtonTypeViewController.h"
  2. @interface QiButton_ButtonTypeViewController ()
  3. @end
  4. @implementation QiButton_ButtonTypeViewController
  5. - (void)viewDidLoad {
  6. [super viewDidLoad];
  7. self.title = @"UIButtonType";
  8. [self buttonType];
  9. }
  10. #pragma mark - Private functions
  11. - (void)buttonType {
  12. NSArray <NSString *>*buttonTypes = @[@"UIButtonTypeCustom",
  13. @"UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0)",
  14. @"UIButtonTypeDetailDisclosure",
  15. @"UIButtonTypeInfoLight",
  16. @"UIButtonTypeInfoDark",
  17. @"UIButtonTypeContactAdd",
  18. @"UIButtonTypePlain API_AVAILABLE(tvos(11.0)) API_UNAVAILABLE(ios, watchos)",
  19. @"7 = UIButtonTypePlain | UIButtonTypeSystem",
  20. @"UIButtonTypeRoundedRect = UIButtonTypeSystem",
  21. @"new a Button"];
  22. CGFloat btnHeight = [UIScreen mainScreen].bounds.size.height / buttonTypes.count;
  23. for (NSInteger buttonTypeI = 0 ; buttonTypeI < buttonTypes.count; buttonTypeI ++) {
  24. UIButton *buttonTypeBtn = [UIButton buttonWithType:buttonTypeI];
  25. // 设置最后的一个按钮 new的方式创建
  26. if (buttonTypeI == buttonTypes.count - 1) {
  27. // 经测试 打印的btn.buttonType 为 UIButtonTypeCustom 观察button的显示样式也是如此
  28. buttonTypeBtn = [UIButton new];
  29. [buttonTypeBtn setImage:[UIImage imageNamed:@"smallQiShareLogo"] forState:UIControlStateNormal];
  30. [buttonTypeBtn setImage:[UIImage imageNamed:@"smallQiShareLogo"] forState:UIControlStateHighlighted];
  31. } else if(buttonTypeI == buttonTypes.count - 2) {
  32. /** 注意UIButtonTypeRoundedRect = UIButtonTypeSystem 真正的值为 1 而不是7
  33. 如果以 [UIButton buttonWithType:7] 方式创建UIButton
  34. 相当于 [UIButton buttonWithType:UIButtonTypePlain | UIButtonTypeSystem];
  35. */
  36. buttonTypeBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  37. [buttonTypeBtn setImage:[UIImage imageNamed:@"smallQiShareLogo"] forState:UIControlStateNormal];
  38. [buttonTypeBtn setImage:[UIImage imageNamed:@"smallQiShareLogo"] forState:UIControlStateHighlighted];
  39. } else if(buttonTypeI == UIButtonTypeCustom || buttonTypeI == UIButtonTypeSystem || buttonTypeI == UIButtonTypeRoundedRect) {
  40. [buttonTypeBtn setImage:[UIImage imageNamed:@"smallQiShareLogo"] forState:UIControlStateNormal];
  41. [buttonTypeBtn setImage:[UIImage imageNamed:@"smallQiShareLogo"] forState:UIControlStateHighlighted];
  42. } else if(buttonTypeI == UIButtonTypeDetailDisclosure || buttonTypeI == UIButtonTypeInfoLight || buttonTypeI == UIButtonTypeInfoDark) {
  43. buttonTypeBtn.showsTouchWhenHighlighted = YES;
  44. }
  45. [self.view addSubview:buttonTypeBtn];
  46. buttonTypeBtn.frame = CGRectMake(.0, buttonTypeI * btnHeight, CGRectGetWidth(self.view.frame), btnHeight);
  47. buttonTypeBtn.backgroundColor = (buttonTypeI % 2 ? [UIColor lightGrayColor] : [UIColor colorWithWhite:0.8 alpha:0.8]);
  48. [buttonTypeBtn setTitle:buttonTypes[buttonTypeI] forState:UIControlStateNormal];
  49. buttonTypeBtn.titleLabel.numberOfLines = 0;
  50. [buttonTypeBtn addTarget:self action:@selector(buttonTypeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  51. }
  52. }
  53. #pragma mark - Action functions
  54. - (void)buttonTypeButtonClicked:(UIButton *)sender {
  55. sender.selected = !sender.selected;
  56. }
  57. @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. spring4.x企业应用开发读书笔记1

    第一章 概述 1 spring 以 ioc 和 aop 为内核,提供了展现层 springMVC.持久层SpringJDBC及业务层事务管理等一站式企业级应用技术. 2spring的特性 方便解耦,简 ...

  2. 如何开发一个npm包并发布到npm中央仓库

    转自: https://liaolongdong.com/2019/01/24/publish-public-npm.html 如何开发一个npm包并发布到npm中央仓库需求背景:平时在项目工作中可能 ...

  3. Hive Authorization

    https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Authorization https://www.cloudera.c ...

  4. servlet 标红的错误笔记

    错误原因,没有添加来自Tomcat服务器的jar包依赖. 解决方法

  5. Oracle spatial空间查询的选择度分析

    在上一篇中,我用一个案例演示了对于数值或字符串类型的字段,选择度的计算方法.并证明了当字段值的选择度不同时,将会影响CBO选择最终的执行计划.对于可排序的字段类型,选择度计算模型已经有很多人写博客介绍 ...

  6. Jenkins+TestNG+gitlab+maven持续集成

    准备工作: 1.安装Jenkins 网上有jenkins安装配置教程 2.jenkins配置 2.1全局工具配置 配置JDK JDK别名:名称可以随意,但是要方便识别 JAVA_HOME:centos ...

  7. IP通信学习心得01

    一.物理拓扑 1. 1) 总线拓扑 特点:所有设备都处于同一个冲突域与广播域,共享相同的带宽 一次只能有一个设备传输,且两端要安装端接器. 传输介质:同轴电缆.(注:10Base5:容量10M 传输5 ...

  8. 从GitLab上创建分支本地拉取项目和提交项目详解

    很多公司前端项目都是部署在GitLab上的,今天我要分享的就是如何从GitLab上创建新的分支并在本地拉取和提交项目 一.在GitLab上面创建自己新的分支 首先你得注册一个账号,登陆之后进入项目Pr ...

  9. Linux中的13个基本Cat命令示例

    cat(“ concatenate ”的缩写)命令是Linux / Unix等操作系统中最常用的命令之一.cat命令允许我们创建单个或多个文件,查看文件包含,连接文件以及在终端或文件中重定向输出.在本 ...

  10. 01-打印Hello World、变量

    一.打印Hello World 下面就是我们写的打印hello world程序 在go语言中://代表单行注释,/**/代表多行注释 //单行注释 /* 多行注释 多行注释 */ package ma ...