UIButton 文本边距/填充

UIButton Text Margin / Padding(UIButton 文本边距/填充)
本文介绍了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 文本边距/填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
BottomAppBar FabCradleMargin becoming less, almost flat, when BottomAppBar returns from being hidden(当BottomAppBar从隐藏状态返回时,BottomAppBar FabCradleMargin变得较少,几乎是平的)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)