【发布时间】:2022-11-29 01:29:38
【问题描述】:
UIButton 标题标签有顶部和底部填充,我想删除填充。
设置 UIButton 内容模式无效。
这是我的代码
lazy var button: UIButton = {
let button = UIButton(type: .custom)
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitleColor(ThemeColor.red, for: .normal)
button.setTitle("Push", for: .normal)
button.addTarget(self, action: #selector(buttonDidTap), for: .touchUpInside)
button.backgroundColor = .blue
button.contentHorizontalAlignment = .fill
button.contentVerticalAlignment = .fill
button.contentMode = .scaleAspectFill
return button
}()
我怎样才能删除填充空间!
【问题讨论】:
-
文档在这里:developer.apple.com/documentation/uikit/uibutton阅读名为 Edge Insets 的部分。
-
你应该设置高度限制 >= 2