UIButton中的三个UIEdgeInsets属性(二)
来源:互联网 发布:射频卡读写软件 编辑:程序博客网 时间:2024/05/16 07:16
接着昨天的UIButton中的三个UIEdgeInsets属性,今天我们具体谈谈UIButton的contentEdgeInsets、titleEdgeInsets、imageEdgeInsets属性。
创建UIButton
UIButton *button = [[UIButton alloc] init];button.frame = CGRectMake(50, 200, 200, 50);[button setTitle:@"我是UIButton" forState:UIControlStateNormal];[button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];[button setBackgroundColor:[UIColor orangeColor]];button.titleLabel.textAlignment = NSTextAlignmentLeft;button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;[self.view addSubview:button];
创建一个button,让button的title居左,以便观察:
UIButton的contentEdgeInsets属性
@property(nonatomic) UIEdgeInsets contentEdgeInsets UI_APPEARANCE_SELECTOR; // default is UIEdgeInsetsZero
contentEdgeInsets里有一个content应该指的就是UIButton的title。
参数含义
上一篇文章我们讲了UIEdgeInsets是个结构体类型。里面有四个参数,分别是:top, left, bottom, right。这四个参数表示距离上边界、左边界、下边界、右边界的距离。
这四个参数的值可以为正值,也可以为负值。拿left举例:
left = 10; //代表以当前位置为基准,向右移动10个像素left = -10; //代表以当前位置为基准,向左移动10个像素
向右移动20个像素
button.contentEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
向右移动20个像素,left = 20,就可以了。
向左移动20个像素
button.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
UIButton的titleEdgeInsets属性
titleEdgeInsets和contentEdgeInsets的作用差不多。我们及设置contentEdgeInsets,又设置titleEdgeInsets,会怎样呢?
button.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);button.contentEdgeInsets = UIEdgeInsetsMake(0, 20 , 0, 0);
看一下效果:
UIButton的titleEdgeInsets属性
创建一个带照片的button
UIButton *button = [[UIButton alloc] init];button.frame = CGRectMake(50, 200, 200, 200);[button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];[button setBackgroundColor:[UIColor orangeColor]];[button setImage:[UIImage imageNamed:@"test"] forState:UIControlStateNormal];[self.view addSubview:button];
运行一下:
向右移动50个像素
button.imageEdgeInsets = UIEdgeInsetsMake(0, 50, 0, 0);
看看效果:
向左移动50个像素
button.imageEdgeInsets = UIEdgeInsetsMake(0, -50, 0, 0);
看看效果:
大家可以自行设置其他三个参数看看效果是怎样的,自己动手便于理解。
0 0
- UIButton中的三个UIEdgeInsets属性(二)
- UIButton中的三个UIEdgeInsets属性(一)
- UIButton里三个UIEdgeInsets属性
- iOS 【UIKit-UIButton中的三个EdgeInsets属性(切图)】
- UIButton-UIEdgeInsets
- iOS UIButton中的三个EdgeInsets属性
- 利用UIEdgeInsets属性修改UIButton的图片,文字位置
- 详解iOS中UIButton的三大UIEdgeInsets属性用法
- 【转】iOS UIButton(UIEdgeInsets)
- UIButton UIEdgeInsets属性改变原有的imageview和titellabel位置,使其变成上下结构
- UIButton的contentEdgeInsets等三个属性介绍
- 关于iOS的UIEdgeInsets属性
- 关于iOS的UIEdgeInsets属性
- UIEdgeInsets
- UIEdgeInsets
- iOS - UIButton(UIEdgeInsets) 设置button上的文字和图片
- (二)html5中的属性
- UIButton属性
- ArrayList的使用方法
- Python re包---正则表达式
- Linux下读取一个目录下的多个文件
- 自定义控件01---简单view的实现
- Android fragment 只让一个fragment支持横屏
- UIButton中的三个UIEdgeInsets属性(二)
- chunked 编码--是什么
- SpringMVC访问静态资源的三种方式
- 死锁怎么检测?
- Android UI框架基本概念
- Windows 7下OpenGL如何配置(网上有教程,这里做部分修改,也是为了方便自己以后使用)
- ibaties 一对多封装
- serializeArray()与 serialize()
- 用正则表达式验证邮箱和手机号