NSAttributedString
storyboardやUILabelのプロパティを操作して装飾をすることができるが、NSAttributedStringを使用することでより細かい装飾をすることができる。
辞書型で指定した文字列の装飾をNSAttibutedStringの引数にいれることによって描画できる
var dictionary:[NSAttributedString.Key: Any] = [
NSAttributedString.Key.font: NSFont.systemFont(ofSize: 40),
NSAttributedString.Key.foregroundColor: NSColor.orange,
NSAttributedString.Key.strokeColor: NSColor.black,
NSAttributedString.Key.strokeWidth: -3
]
//辞書型を引数(attributeds)に入れる。
let attrString = NSAttributedString(string: "Swift", attributes: dic)
storyboardだとどうしてもうまく表現されないことも多々あったり、動的に文字列をうまく変更したい場合はよく使うものかな
それぞれのvalueは色が入ったり、サイズが入ったり、セットで描画されるのもあるので拡張機能として、再利用可能な形にしてから使い回す使用方法が多い。