NSTextView 研究(1)

这次研究的目标是 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值