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. 读取Cert格式证书的密钥

    不想存储Cert证书内容,只想存储证书密钥,可通过以下实现读取证书的密钥出来: package com.zat.ucop.service.util; import sun.misc.BASE64Enc ...

  2. MySQL数据表的修改

    数据表的修改包括列的增加.列的删除.约束的添加.约束的删除等. 添加单列 ALTER TABLE tbl_name ADD [COLUMN] col_name column_definition [F ...

  3. Robot Framework自动化测试四(分层思想)

    谈到Robot  Framework 分层的思想,就不得不提“关键字驱动”. 关键字驱动: 通过调用的关键字不同,从而引起测试结果的不同. 在上一节的selenium API 中所介绍的方法其实就是关 ...

  4. jqueyr validtion的使用

    江北机场对validtion的扩展 <script type="text/javascript"> $.validator.setDefaults({ /*关闭键盘输入 ...

  5. linq——常用方法

    take  前几 skip   跳过前几 takeWhile   var firstNumbersLessThan6 = numbers.TakeWhile(n => n < 6);  / ...

  6. PHP学习4——面向对象

    主要内容: 创建类 成员方法 构造方法 析构方法 封装 继承 接口 多态 静态成员 常用关键字 常用魔术方法 从PHP5开始引入了面向对象的全部机制,面向对象的特性符合软件工程的3个目标:重用性,灵活 ...

  7. docker安装Ghost博客

    1.安装docker-compose curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose ...

  8. [android] 界面切换的简单动画

    1. 新建个位移动画的xml文件 Activity中开启动画 使用AnimationUtils类加载动画资源文件 left_to_right.xml <?xml version="1. ...

  9. 前端(二):css样式

    本节笔记根据css中文手册整理,内容已做成思维导图.下载地址https://files.cnblogs.com/files/kuaizifeng/css.xmind.zip. css(Csacadin ...

  10. SZU4

    #include <iostream> #include <string> #include <cstring> #include <cstdlib> ...