这次研究的目标是 NSTextView 控件的文本处理图片处理问题
这是一个初步演示,在这里我们建立一个类来处理文本的写入问题。你建立一个Cocoa工程,然后在View里拖入一个NSTextView对象,并在
ViewController类中添加 textView 变量。然后在 viewDidLoad() 函数中添加代码。令人你需要找一个girl.jpg文件,也拖入工程。
用到的代码全部列在后面,就不解释了。
里面添加代码。
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let attachmentCell = NSTextAttachmentCell(imageCell: NSImage(named: "girl.jpg"))
let attachment = NSTextAttachment()
attachment.attachmentCell = attachmentCell
let attributedStr = NSAttributedString(attachment: attachment)
self.textView.textStorage?.insert(attributedStr, at: 0)
let designer = TextAttributedDesigner("Designer Example")
designer.newline()
designer.append("ForegroundColor", attrType: .foregroundColor(NSColor.blue))
designer.newline()
designer.append("BackgroundColor", attrType: .backgroundColor(NSColor.lightGray))
designer.newline()
designer.append("Font (Cochin-BoldItalic)", attrType: .font(NSFont(name: "Cochin-BoldItalic", size: 30)!))
designer.newline()
let para = NS