相关疑难解决方法(0)

Autolayout - UIButton的内在大小不包括标题插入

如果我使用autolayout安排了UIButton,它的大小可以很好地调整以适应其内容.

如果我将图像设置为button.image,则内在大小似乎再次考虑到这一点.

但是,如果我调整titleEdgeInsets按钮的按钮,布局不会考虑到这一点,而是截断按钮标题.

如何确保按钮的固有宽度占据插入?

在此输入图像描述

编辑:

我使用以下内容:

[self.backButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
Run Code Online (Sandbox Code Playgroud)

目标是在图像和文本之间添加一些分隔.

cocoa-touch uibutton uiview ios autolayout

184
推荐指数
9
解决办法
7万
查看次数

iOS:UIButton根据文本长度调整大小

在界面构建器中,按住Command+ =将调整按钮的大小以适合其文本.我想知道在按钮添加到视图之前是否可以以编程方式执行此操作.

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button.titleLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:12]];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
// I need to know the width needed to accomodate NSStringVariable
[button setTitle:NSStringVariable forState:UIControlStateNormal]; 
// So that I can set the width property of the button before addSubview
[button setFrame:CGRectMake(10, 0, width, fixedHeight)];
[subNavigation addSubview:button];
Run Code Online (Sandbox Code Playgroud)

uibutton ios

126
推荐指数
11
解决办法
13万
查看次数

标签 统计

ios ×2

uibutton ×2

autolayout ×1

cocoa-touch ×1

uiview ×1