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

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

问题描述

我有以下布局,我正在尝试向左右添加填充..

这些控件是一个禁用的 UIButton.

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

UIButton *buttonTime = [[UIButton alloc] initWithFrame:CGRectMake(90, 10, 50, 20)];[buttonTime setBackgroundImage:[[UIImage imageNamed:@"bubble.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:13] forState:UIControlStateDisabled];[buttonTime setTitle:@"2011 年 2 月 27 日晚上 11:10" 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];[按钮时间释放];

解决方案

//Swiftvar titleEdgeInsets: UIEdgeInsets!//目标-C@property(nonatomic) UIEdgeInsets titleEdgeInsets;

<块引用>

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

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

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

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;

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天全站免登陆