【发布时间】:2020-05-01 23:43:12
【问题描述】:
不知道该怎么做。我发现了一个自定义 NSButton 类的代码块,它可以检查字体大小和颜色的属性,仅此而已。有没有办法将我的 Mac 上的字体集添加到我可以为这个类更改的属性中,或者获取我在其他可设置属性中设置的字体,比如标题?这是课程:
import Cocoa
class TextButton: NSButton {
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
// Drawing code here.
}
@IBInspectable open var textColor: NSColor = NSColor.black
@IBInspectable open var textSize: CGFloat = 10
public override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
}
override func awakeFromNib() {
let titleParagraphStyle = NSMutableParagraphStyle()
titleParagraphStyle.alignment = alignment
let attributes: [NSAttributedString.Key : Any] = [.foregroundColor: textColor, .font: NSFont.boldSystemFont(ofSize: textSize), .paragraphStyle: titleParagraphStyle]
self.attributedTitle = NSMutableAttributedString(string: self.title, attributes: attributes)
}
}
【问题讨论】:
标签: swift xcode fonts nsbutton