UIButton中的**EdgeInsets是做什么用的?

UIEdgeInsetsMake

Creates an edge inset for a button or view.
An inset is a margin around the drawing rectangle where each side (left, right, top, and bottom) can have a different value.

给一个button或者view创建一个嵌入的边缘.

inset是一个矩形view页边空白,每一边都可以设定一个不同的值.

图片素材: 1@2x.png

- (void)viewDidLoad
{
[super viewDidLoad]; UIButton *normalButton = nil;
UIButton *edgeButton = nil; // normalButton
{
// 初始化按钮
normalButton = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];
normalButton.backgroundColor = [UIColor blackColor]; // 按钮图片
[normalButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
} // EdgeButton
{
// 初始化按钮
edgeButton = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];
edgeButton.backgroundColor = [UIColor blackColor]; // 按钮图片
[edgeButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal]; // 设置图片间距
edgeButton.imageEdgeInsets = UIEdgeInsetsMake(, , , );
} [self.view addSubview:normalButton];
[self.view addSubview:edgeButton];
}

viewDidLoad

以下是模拟器显示结果:

从结果中可以看到,设置了图片的imageEdgeInsets后,图片显示被缩放了哦.

再来测试文本的titleEdgeInsets

- (void)viewDidLoad
{
[super viewDidLoad]; UIButton *normalButton = nil;
UIButton *edgeButton = nil; // normalButton
{
// 初始化按钮
normalButton = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];
normalButton.backgroundColor = [UIColor blackColor]; [normalButton setTitle:@"Y.X." forState:UIControlStateNormal];
[normalButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
} // EdgeButton
{
// 初始化按钮
edgeButton = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];
edgeButton.backgroundColor = [UIColor blackColor]; [edgeButton setTitle:@"Y.X." forState:UIControlStateNormal];
[edgeButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; edgeButton.titleEdgeInsets = UIEdgeInsetsMake(, , , );
} [self.view addSubview:normalButton];
[self.view addSubview:edgeButton];
}

viewDidLoad

以下是运行结果:

文本并没有缩放的说,再试试这么设置:

UIButton还有一个属性叫contentEdgeInsets.

Use this property to resize and reposition the effective drawing rectangle for the button content. The content comprises the button image and button title.

实际上,这个contentEdgeInsets是用来同时设置imageEdgeInsets与titleEdgeInsets的,没什么特别的,就不举例子了:)

UIButton中的**EdgeInsets是做什么用的?的更多相关文章

  1. 格而知之1:UIButton中imageView和titleLabel的位置调整

    在使用UIButton时,有时候需要调整按钮内部的imageView和titleLabel的位置和尺寸.在默认情况下,按钮内部的imageView和titleLabel的显示效果是图片在左文字在右,然 ...

  2. 解决:"不再sudoers文件中,此事将不做被报告”的问题

    使用sudo出现问题:不再sudoers文件中,此事将不做被报告 系统:win8.1 +cents 7 问题:在虚拟机中,默认不是root账号,在使用sudo命令时候收到下面警告: sudo命令含义: ...

  3. PMO在组织中实现价值应做的工作

    PMO在组织中实现价值应做的工作 研发人员及项目经理常常对PMO有反感情绪,认为其不熟悉业务流程与技术.经常要求项目经理和研发人员提交形式化的材料,只审批和监控,不能为项目提供良好的服务.在很多企业, ...

  4. ios开发之--UIButton中imageView和titleLabel的位置调整

    在使用UIButton时,有时候需要调整按钮内部的imageView和titleLabel的位置和尺寸.在默认情况下,按钮内部的imageView和titleLabel的显示效果是图片在左文字在右,然 ...

  5. API接口自动化之3 同一个war包中多个接口做自动化测试

    同一个war包中多个接口做自动化测试 一个接口用一个测试类,每个测试用例如下,比如下面是4个测试用例,每个详细的测试用例中含有请求入参,返回体校验,以此来判断每条测试用例是否通过 一个war包中,若含 ...

  6. UIButton中的三个UIEdgeInsets属性

    接着昨天的 UIButton中的三个UIEdgeInsets属性 ,今天我们具体谈谈UIButton的contentEdgeInsets.titleEdgeInsets.imageEdgeInsets ...

  7. C#中如何防止Excel做科学计算法转换

    C#中如何防止Excel做科学计算法转换  string style = @"<style>.text{mso-number-format:\@;}</style>& ...

  8. Python中实现对list做减法操作介绍

    Python中实现对list做减法操作介绍 这篇文章主要介绍了Python中实现对list做减法操作介绍,需要的朋友可以参考下 问题描述:假设我有这样两个list, 一个是list1,list1 = ...

  9. 技术分享 | 在GreatDB分布式部署模式中使用Chaos Mesh做混沌测试

    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 1. 需求背景与万里安全数据库软件GreatDB分布式部署模式介绍 1.1 需求背景 混沌测试是检测分布式系统不确定性.建 ...

随机推荐

  1. ionic3 引入第三方库(jquery)

    安装 npm install jquery npm install @types/jquery 在需要的ts文件中引入,一定要在最顶端 import * as $ from '../../../nod ...

  2. docker volumes?

    我发现我无法mount东西出来.都是会被host的覆盖掉的.,

  3. zato集群部署

    注: SQL ODB和Cluster’s config需要首先依次创建,其他三个次序随意 对不熟悉的命令,使用server create *** -h 查看帮助文档 修改完后配置文件,要重启(zato ...

  4. win10中VirtualBox联网设置

    <分享>关于win10操作系统中VirtualBox无法桥接的解决方法 版权声明:本文为博主原创文章,未经博主允许不得转载. 升级win10,本来是一件很好的事,想好好体验一下新版本的感觉 ...

  5. java并发编程(2)线程池的使用

    一.任务和执行策略之间的隐性耦合 Executor可以将任务的提交和任务的执行策略解耦 只有任务是同类型的且执行时间差别不大,才能发挥最大性能,否则,如将一些耗时长的任务和耗时短的任务放在一个线程池, ...

  6. 架构实战项目心得(五):mysql安装

    1.  yum安装mysql yum -y install mysql-server 2.  启动mysql服务 启动mysql:service mysqld start 查看mysql的状态:ser ...

  7. 问题集录04--json和jsonp讲解

    JSON和JSONP  JSON(Javascript Object Notation)是一种轻量级的数据交换格式,用于在浏览器和服务器之间交换信息.  JSONP(JSON With Padding ...

  8. Linux学习笔记之(1)~Linux有趣的历史概览

    献给知道mono,了解Jexus,对.net混搭技术感兴趣的朋友. 1965年,Bell.MIT和GE公司发起Multics计划,目标是实现一个操作系统可以让大型主机实现连接三百个终端的目标.(那个时 ...

  9. redis(6)lua脚本

    一.lua脚本 lua是一种轻量小巧的脚本语言,用标准的C语言编写并以源代码形式开放,其设计目的是为了嵌入应用程序中,从而为应用程序提供灵活的扩展和定制功能. lua的详细内容你可以参考lua官方网站 ...

  10. 十、集成使用redis

    一.简介 redis是一种非关系型数据库,它的数据结构是key-value的存储形式:能够支持多种类型的数据存储,如:string/list/map/object...等.springboot自然也对 ...