【发布时间】:2020-09-16 07:32:02
【问题描述】:
您必须使用属性文本来进行字距调整。但。另一方面,您无法在 IB 属性文本菜单中获取系统字体。
我如何(在代码中)创建一个UIButton,它有
- 系统字体,粗体粗体
- 尺寸 11
- kern 属性设置为 -2
理想情况下,它会从 IB 中的纯文本标题中收集按钮的文本。但是,如果必须在代码中设置文本,那很好。
class NiftyButton: UIButton {
????
}
通常我像这样初始化 UIButton .. 但我什至不知道这是否是最好的地方? (你不能在 layoutSubviews 中这样做,因为它当然会循环。)
class InitializeyButton: UIButton {
override init(frame: CGRect) {
super.init(frame: frame)
common()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
common()
}
func common() {
...
}
}
如何在代码中实现...
- 系统字体,粗体粗体
- 尺寸 11
- kern 属性设置为 -2
【问题讨论】:
-
您可以在 Interface Builder 中不使用“代码”来完成。我让它适用于字距调整、大小字体和粗体,但无法指定系统之一。只有一个有名字的。
-
没错,所以问题来了,Larme!
标签: ios swift uibutton nsattributedstring