我知道有一些关于此的 SO 帖子,但没有一个有效......
我只是想使用
UIButton.Configuration
方法获取我的自定义 UIButton 子类,以 强制我的标题标签保持 1 行,而不更改按钮框架。
我不断得到如下所示的正确按钮...
我能做什么??这是我通过按钮设置的方式..
init(withTitle title: String, ... <more custom params> ...) {
// ...
super.init(frame: .zero)
var config = UIButton.Configuration.filled()
config.title = title
titleLabel?.lineBreakMode = .byTruncatingTail
titleLabel?.numberOfLines = 1
configurationUpdateHandler = { button in
// ... here I handle colorizing elements for different button states /
}
}
我知道我可以通过使用标准
let button = UIButton(type: .custom)
完成文本剪辑,并设置titleLabel
行属性。这不是解决方案 - 否则无法使用配置提供的定制。
UIButton.Configuration
对象指定换行模式为:
var config = UIButton.Configuration.filled()
config.titleLineBreakMode = .byTruncatingTail
myButton.config = config