UIButton Text Margin / Padding(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 文本边距/填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIButton 文本边距/填充
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01