相关疑难解决方法(0)

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/xcode:设置按钮的可见宽度

这应该很简单,但是我在设置故事板中带有占位符的文本字段和/或按钮的宽度时遇到了麻烦,以便它在模拟器中看起来正确..

我已将宽度设置为 200。它看起来在故事板中找到,但是,当我构建和运行时,文本字段会缩小到占位符的大小。

在按钮的情况下,我还将宽度设置为 200,但按钮​​缩小到标签的大小。

我做错了什么?

xcode width ios

3
推荐指数
1
解决办法
3222
查看次数

标签 统计

ios ×2

uibutton ×1

width ×1

xcode ×1