UIButton文本边距/填充 [英] UIButton Text Margin / Padding

查看:239
本文介绍了UIButton文本边距/填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下布局,并且我正在尝试在左侧和右侧添加填充.

I have the following layout, and I'm trying to add a padding to the left and right..

控件是禁用的UIButton.

The controls are a disabled UIButton.

我创建按钮的代码是这样的:

My code for creating a button is this:

UIButton *buttonTime = [[UIButton alloc] initWithFrame:CGRectMake(90, 10, 50, 20)]; 
[buttonTime setBackgroundImage:[[UIImage imageNamed:@"bubble.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:13] forState:UIControlStateDisabled];

[buttonTime setTitle:@"27 feb, 2011 11:10 PM" forState:UIControlStateDisabled];             
[buttonTime setTitleColor:[UIColor blackColor] forState:UIControlStateDisabled];
buttonTime.titleLabel.font=[UIFont fontWithName:@"Helvetica" size:8.0]; 
buttonTime.titleLabel.lineBreakMode= UILineBreakModeWordWrap;
[buttonTime setEnabled:FALSE];
[scrollView addSubview:buttonTime];
[buttonTime release];

推荐答案

// Swift
var titleEdgeInsets: UIEdgeInsets!

// Objective-C
@property(nonatomic) UIEdgeInsets titleEdgeInsets;

使用此属性来调整按钮标题的有效绘图矩形的大小和位置.您可以为四个插图(上,左,下,右)中的每一个指定不同的值.正值会缩小或插入该边缘,将其移到更靠近按钮中心的位置.负值扩展或起始于该边缘.使用UIEdgeInsetsMake函数构造此属性的值.默认值为UIEdgeInsetsZero.

Use this property to resize and reposition the effective drawing rectangle for the button title. You can specify a different value for each of the four insets (top, left, bottom, right). A positive value shrinks, or insets, that edge—moving it closer to the center of the button. A negative value expands, or outsets, that edge. Use the UIEdgeInsetsMake function to construct a value for this property. The default value is UIEdgeInsetsZero.

https://developer.apple.com/documentation/uikit/uibutton/1624010-titleedgeinsets

这篇关于UIButton文本边距/填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆