private static let boarderWidth: CGFloat = 2.0
- private let layoutManager: NSLayoutManager
- private let textContainer: NSTextContainer
+ private let layoutManager = NSLayoutManager()
+ private let textContainer = NSTextContainer()
required init(coder: NSCoder) {
-
- layoutManager = NSLayoutManager()
- textContainer = NSTextContainer()
-
+
super.init(coder: coder)
layoutManager.addTextContainer(textContainer)
let attribute = attributedString.attributes(at: 0, effectiveRange: nil)
- guard let forgroundColor = attribute[NSForegroundColorAttributeName] as? NSColor
- else { return }
+ guard let forgroundColor = attribute[.foregroundColor] as? NSColor else {
+
+ return
+ }
- if forgroundColor == NSColor.controlTextColor {
+ if forgroundColor == .controlTextColor {
super.drawInterior(withFrame: cellFrame, in: controlView)
return
}
- guard let font = attribute[NSFontAttributeName] as? NSFont
- else { return }
+ guard let font = attribute[.font] as? NSFont else {
+
+ return
+ }
let textStorage = NSTextStorage(string: attributedString.string, attributes: attribute)
textStorage.addLayoutManager(layoutManager)
let nsGlyph = UnsafeMutablePointer<NSGlyph>.allocate(capacity: range.length)
- // TODO: use forEach
- for i in 0...range.length {
-
- nsGlyph[i] = NSGlyph(glyph[i])
- }
+ (0..<range.length).forEach { nsGlyph[$0] = NSGlyph(glyph[$0]) }
let path = NSBezierPath()
path.move(to: point)