【发布时间】:2010-10-10 22:00:31
【问题描述】:
我有以下代码...
UILabel *buttonLabel = [[UILabel alloc] initWithFrame:targetButton.bounds];
buttonLabel.text = @"Long text string";
[targetButton addSubview:buttonLabel];
[targetButton bringSubviewToFront:buttonLabel];
...我的想法是我可以为按钮设置多行文本,但文本总是被 UIButton 的 backgroundImage 遮挡。显示按钮子视图的日志调用显示已添加 UILabel,但无法看到文本本身。这是 UIButton 中的错误还是我做错了什么?
【问题讨论】:
-
button.titleLabel?.numberOfLines = 0 -
注意这个非常古老的 QA,在现代 Xcode 中非常简单,选择“ATTRIBUTED TEXT” 然后很简单,选择“字符换行”。
-
另见updated answer 类似问题。
-
看到这个答案(多行,适合宽度,适合高度)按钮文本stackoverflow.com/a/59211399/7523163
-
iOS 15 现已免费提供此功能⟹ developer.apple.com/videos/play/wwdc2021/10059/?time=641 ????
标签: ios objective-c cocoa-touch uibutton uikit