UIButton中的**EdgeInsets是做什么用的?
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:UIButton中imageView和titleLabel的位置调整
在使用UIButton时,有时候需要调整按钮内部的imageView和titleLabel的位置和尺寸.在默认情况下,按钮内部的imageView和titleLabel的显示效果是图片在左文字在右,然 ...
- 解决:"不再sudoers文件中,此事将不做被报告”的问题
使用sudo出现问题:不再sudoers文件中,此事将不做被报告 系统:win8.1 +cents 7 问题:在虚拟机中,默认不是root账号,在使用sudo命令时候收到下面警告: sudo命令含义: ...
- PMO在组织中实现价值应做的工作
PMO在组织中实现价值应做的工作 研发人员及项目经理常常对PMO有反感情绪,认为其不熟悉业务流程与技术.经常要求项目经理和研发人员提交形式化的材料,只审批和监控,不能为项目提供良好的服务.在很多企业, ...
- ios开发之--UIButton中imageView和titleLabel的位置调整
在使用UIButton时,有时候需要调整按钮内部的imageView和titleLabel的位置和尺寸.在默认情况下,按钮内部的imageView和titleLabel的显示效果是图片在左文字在右,然 ...
- API接口自动化之3 同一个war包中多个接口做自动化测试
同一个war包中多个接口做自动化测试 一个接口用一个测试类,每个测试用例如下,比如下面是4个测试用例,每个详细的测试用例中含有请求入参,返回体校验,以此来判断每条测试用例是否通过 一个war包中,若含 ...
- UIButton中的三个UIEdgeInsets属性
接着昨天的 UIButton中的三个UIEdgeInsets属性 ,今天我们具体谈谈UIButton的contentEdgeInsets.titleEdgeInsets.imageEdgeInsets ...
- C#中如何防止Excel做科学计算法转换
C#中如何防止Excel做科学计算法转换 string style = @"<style>.text{mso-number-format:\@;}</style>& ...
- Python中实现对list做减法操作介绍
Python中实现对list做减法操作介绍 这篇文章主要介绍了Python中实现对list做减法操作介绍,需要的朋友可以参考下 问题描述:假设我有这样两个list, 一个是list1,list1 = ...
- 技术分享 | 在GreatDB分布式部署模式中使用Chaos Mesh做混沌测试
GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 1. 需求背景与万里安全数据库软件GreatDB分布式部署模式介绍 1.1 需求背景 混沌测试是检测分布式系统不确定性.建 ...
随机推荐
- c# 如何得到一个字符的ASCII码
'; int b = (int)a; 就这么简单..
- 【javascript】javascript学习之js脚本的解析步骤
将javascript代码加入到HTML代码中,即使用<script>标签的方式有两种:直接嵌入页面中和使用外部js文件. 使用<script>标签嵌入html代码中时,需要指 ...
- 【Css】Layout布局(二)
css定位(Positioning) 所谓定位,即允许你定义元素框相对于其正常位置应该出现的位置,或者相对于父元素.另一个元素甚至浏览器窗口本身的位置. css提供了三种基本的定位机制:普通流.浮动和 ...
- css选择器星号(*)
1.星号(*)选择器的优先级 css的(*)选择器,也是通用选择器,对所有的页面元素(html,title,style,body,div,p……)应用样式,级别最低 在选择器的级别中:在元素名< ...
- Vim常用插件——前端开发工具系列
作为一名开发者,应该对编辑器之神Vim与神之编辑器Emacs有所耳闻吧.编辑器之战的具体细节有兴趣的童鞋可以google之. Vim最大的特点是打开速度快,功能强大,一旦掌握了其中的命令,编程过程双手 ...
- mysql 优化常用语句
show status;//查询mysql各种状态: show variables like 'long_query_time';//慢查询的限定时间 set long_query_time=1;// ...
- SQL Server修改表结构,不允许保存更改。
当修改表结构时,sql server会弹出对话框,显示以下内容: 不允许保存更改.您所做的更改要求删除并重新创建以下表.您对无法重新创建的表进行了更改或者启用了“阻止保存要求重新创建表的更改”选项. ...
- C++测验代码
/* 返回字符串前n位和返回整数前n位 */ #include <iostream> unsigned long left(unsigned long num, int n); char ...
- Spring相关概念的理解理解
spring 框架的优点是一个轻量级比较简单易学的框架,实际使用中的有点优点有哪些呢!1.降低了组件之间的耦合性 ,实现了软件各层之间的解耦 2.可以使用容易提供的众多服务,如事务管理,消息服务等 3 ...
- About custom Theme and Style
For android system, of course you can custom your own style and theme, but you can't break compatibi ...