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. MySQL 查询结果分组 group by

    [group by {col_name | position} [ASC | DESC ]] 分组条件 [HAVING where_condition] HAVING 后面的条件必须出现在select ...

  2. selenium+Python(Js处理click失效)

    有时候元素明明已经找到了,运行也没报错,点击后页面没任何反应.这种问题遇到了,是比较头疼的,因为没任何报错,只是 click 事件失效了. 问题: 1.在练习百度的搜索设置按钮时,点保存设置按钮,al ...

  3. 在ubuntu下使用Eclipse搭建Hadoop开发环境

    一.安装准备1.JDK版本:jdk1.7.0(jdk-7-linux-i586.tar.gz)2.hadoop版本:hadoop-1.1.1(hadoop-1.1.1.tar.gz)3.eclipse ...

  4. linux系统下图片的路径

    1. 图片跟网页或者程序在同一目录下 直接 src="abc.jpg" 如果不行 就加多一个斜杠 src="/abc.jpg"

  5. 九度oj题目1555:重复子串

    题目1555:重复子串 时间限制:3 秒 内存限制:256 兆 特殊判题:否 提交:738 解决:125 题目描述: 给定一个由小写字母组成的字符串,求它的所有连续子串中,出现过至少两次,且至少有一对 ...

  6. Golang教程:循环语句

    循环语句用于重复执行一段代码. for 语句是 Go 中唯一的循环语句.Go 没有提供其他语言(如 C)中的 while 和 do while 语句. for 语句语法 for 语句的语法如下: fo ...

  7. Codeforces 543E. Listening to Music

    Description 题面 Solution 分块套分块,分别对时间和位置进行分块 差不多是一个定期保存信息的方法 对于询问我们不妨求出 \(>=x\) 的答案,然后用 \(m-(>=x ...

  8. MySql 模糊连接

    我们有时候会遇到比较扯的数据库设计,也可能处于某种原因,或当时特殊考虑,情况类似如下: 表A,主键Id: 表B,关联字段 = 表A的Id的逗号连接,如:1009,2393,1235 B表的一行,对应A ...

  9. Silverlight & Blend动画设计系列一:偏移动画(TranslateTransform)

    用户界面组件.图像元素和多媒体功能可以让我们的界面生动活泼,除此之外,Silverlight还具备动画功能,它可以让应用程序“动起来”.实际上,英文中Animation这个单词的意思是给某物带来生命. ...

  10. Azure 上 Linux 虚拟机 Mac 地址的持久化

    有些用户在使用 Azure Linux 虚拟机安装软件时,有些软件的 license 会和当前系统的 mac 地址绑定,那么在 Azure VM 重启,reszie(改变尺寸大小),停止然后再启动的时 ...