iOS UIButton 自定义图片和文字位置详解
来源:互联网 发布:淘宝买球星卡 编辑:程序博客网 时间:2024/05/13 17:29
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;
在UIButton中有三个对EdgeInsets的设置:ContentEdgeInsets、titleEdgeInsets、imageEdgeInsets
@property(nonatomic) UIEdgeInsets contentEdgeInsets UI_APPEARANCE_SELECTOR; // default is UIEdgeInsetsZero@property(nonatomic) UIEdgeInsets titleEdgeInsets; // default is UIEdgeInsetsZero@property(nonatomic) BOOL reversesTitleShadowWhenHighlighted; // default is NO. if YES, shadow reverses to shift between engrave and emboss appearance@property(nonatomic) UIEdgeInsets imageEdgeInsets; // default is UIEdgeInsetsZero
UIEdgeInsetsMake
里面的四个参数表示距离上边界、左边界、下边界、右边界的距离,默认都为零,title/image在button的正中央
UIKIT_STATIC_INLINE UIEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) { UIEdgeInsets insets = {top, left, bottom, right}; return insets;}
UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)]; button.frame = CGRectMake(50, 50, 200, 60); [button addTarget:self action:@selector(click:) forControlEvents:(UIControlEventTouchUpInside)]; [button setTitle:@"点击我啊" forState:(UIControlStateNormal)]; [button setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; button.backgroundColor = [UIColor blackColor]; [button setImage:[UIImage imageNamed:@"icon_pass"] forState:(UIControlStateNormal)]; // 默认的是图片在左title 在右 // 1,图片在右边,title 在左边 可以调左边距 也可以调右边距// button.imageEdgeInsets = UIEdgeInsetsMake(0,0,0,-150);// 和(0,150,0,0) 一样效果// button.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0,50); // (0,-50,0,0) 一样效果 // 2 图片在上 title 在下面 // 具体数字可以自己调 button.imageEdgeInsets = UIEdgeInsetsMake(- 20,50,0,0); button.titleEdgeInsets = UIEdgeInsetsMake(32, 0, 0,0); [self.view addSubview:button];
0 0
- iOS UIButton 自定义图片和文字位置详解
- ios UIButton的图片和文字位置
- 自定义UIButton上的文字和图片位置
- uibutton 改变文字和图片的位置
- 自定义 UIButton(图片+文字)
- 自定义UIButton图片和文字的frame
- iOS心得7 按钮的图片和文字自定义位置
- iOS UIButton 图片和文字上下居中
- iOS UIButton 图片和文字布局调整
- iOS - UIButton(UIEdgeInsets)/设置button上的文字和图片 在定义位置
- 28.iOS - UIButton(UIEdgeInsets)/设置button上的文字和图片 在定义位置
- iOS - UIButton(UIEdgeInsets)/设置button上的文字和图片 在定义位置
- iOS经典讲解之UIButton改变图片和文字的位置
- [IOS笔记]改变UIButton中图片和文字的位置 xib与故事版的差别
- UIButton图片文字位置调整
- iOS -- UIButton上的文字、图片位置的调整
- iOS UIButton调整图片与文字的位置
- UIButton上的图片和文字位置调整
- dubbo与zookeeper搭建类soa服务
- 绝对定位 与 z-index
- selenium元素总结
- linux 下操作Mysql系列文章一
- 图片加载库Fresco
- iOS UIButton 自定义图片和文字位置详解
- linux(centos6) 安装mysql5.7
- iOS开发-图片高斯模糊效果
- Makefile 中:= ?= += =的区别
- plsqldev报错: the password will expire within 5 days 解决方法
- 编译并使用boost库(win7+boost1.60+vs2013)
- 利用position定位和hover实现鼠标滑过文字覆盖图片效果
- GDOI2016总结
- Angular中的内置指令和自定义指令