0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

NSTextView に font や color を設定する

Last updated at Posted at 2020-07-20
let view = NSTextView()
view.delegate = context.coordinator
view.string = text
view.font = NSFont.systemFont(ofSize: NSFont.systemFontSize*1.3, weight: .regular)
view.backgroundColor = NSColor(cgColor: CGColor(red: 0, green: 10, blue: 10, alpha: 10))!

NSTextView へ何かを施そうとするといちいち難しいので、備忘録です。

let view = NSTextView()
let font = NSFont.systemFont(ofSize: NSFont.systemFontSize*1.3, weight: .regular)
let paragraphStyle = NSMutableParagraphStyle()
        
paragraphStyle.alignment = .left
paragraphStyle.firstLineHeadIndent = 0.0
paragraphStyle.lineSpacing = 8.0

let attributes: [NSAttributedString.Key: Any] = [
    .font: font,
    .paragraphStyle: paragraphStyle
]
        
let attrString = NSAttributedString(string: text, attributes: attributes)
view.textStorage?.append(attrString)
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?