UIButton中的三个UIEdgeInsets属性(一)

来源:互联网 发布:济宁淘宝订餐 编辑:程序博客网 时间:2024/06/04 20:00

今天是周六,不知道正在看文章的你有没有在加班。没有加班的,就好好休息一下吧;加班的,我只能同情一下啦。今天我们来看看UIButton中的三个UIEdgeInsets属性。

UIEdgeInsets是什么

UIEdgeInsets是什么?我们点进去看一下:

typedef struct UIEdgeInsets {    CGFloat top, left, bottom, right;  // specify amount to inset (positive) for each of the edges. values can be negative to 'outset'} UIEdgeInsets;

UIEdgeInsets是个结构体类型。里面有四个参数,分别是:top, left, bottom, right。这四个参数表示距离上边界、左边界、下边界、右边界的距离。

哪三个UIEdgeInsets属性

不知道大家发现没有,UIButton里面有三个UIEdgeInsets属性,分别是:

@property(nonatomic)          UIEdgeInsets contentEdgeInsets UI_APPEARANCE_SELECTOR; // default is UIEdgeInsetsZero@property(nonatomic)          UIEdgeInsets titleEdgeInsets;                // default is UIEdgeInsetsZero@property(nonatomic)          UIEdgeInsets imageEdgeInsets;                // default is UIEdgeInsetsZero

contentEdgeInsets后面有个UI_APPEARANCE_SELECTOR是什么意思呢?

提示:UI_APPEARANCE_SELECTOR标记的属性都支持通过外观代理来定制。

举例,设置UIButton的contentEdgeInsets属性,可以直接调用:

[[UIButton appearance] setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

关于UIButton三个UIEdgeInsets属性的作用,下一篇文章介绍。

原文链接:http://www.superqq.com/blog/2015/07/03/uibuttonzhong-de-san-ge-uiedgeinsetsshu-xing-(%5B%3F%5D-)/

0 0
原创粉丝点击