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. python 流式游标读取mysql大型数据库

    import asyncio import aiomysql async def dbdaochu(loop): sqlstr='sql' conn = await aiomysql.connect( ...

  2. 如何为 Vue 项目写单元测试

    https://www.w3ctech.com/topic/2052 如何为 Vue 项目写单元测试 前端工程 明非 2017-07-18 4685 访问 1 分享 微信分享 译者:明非 链接:htt ...

  3. 如何应用前端技术唤起app及判断用户来源及与原生交互的原理

    做唤起时需要native端进行配合, h5唤起app这种需求是常见的.在移动为王的时代,h5在app导流上发挥着重要的作用. 目前我们采用的唤起方式是url scheme(iOS,Android平台都 ...

  4. TSM_ISSUE_123

    dsmc 命令详解http://www-ik.fzk.de/~apel/html/adsm_manual.htmlTSM InfoCenterhttp://www-01.ibm.com/support ...

  5. MySQL对结果进行排序order by

    order by {col_name | expr | position} [ASC | DESC] 查询结果     排序条件的顺序  决定   排序条件   的优先级 如果同一条件下值相等,那么启 ...

  6. XAMPP中Apache和Mysql启动失败问题总结

    一.Apache启动失败 xampp启动时显示的错误为: 9:52:41  [Apache]  Attempting to start Apache app... 9:52:41  [Apache]  ...

  7. ES6内容

    iterator 遍历器iterator makeIterator是个遍历器,生成遍历器对象it var it = makeIterator(['a', 'b']); it.next() // { v ...

  8. 江铖:乳腺癌识别By AI

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由云加社区技术沙龙 发表于云+社区专栏 演讲嘉宾:江铖,腾讯觅影高级研究员.多年以来一直从事计算机视觉相关的研究.加入腾讯以后,负责腾讯 ...

  9. 翻屏类 h5 适配方案:解决宽高自适应难题

    表格 图片等 宽度自适应  :width:100%;  box-sizing: border-box; 基于淘宝适配方案flexible + 翻屏h5 适配方案adaptive flexible解读及 ...

  10. net 记录controller Action耗时

    可能有些时候需要记录Action的执行时间来优化系统功能,这时可以用过滤器来实现 第1个例子 using System; using System.Diagnostics; using System. ...