簡體   English   中英

串聯2 NSAttributedString

[英]Concatenate 2 NSAttributedString

我正在嘗試連接2 NSAttributedString。 但是它給我一個錯誤,該方法不可用,而該方法可用。 這是我的代碼:

let def = "I am using here <ul><li>Coffee</li><li>Tea</li><li>Milk</li></ul> <br/> <a href='http://www.w3schools.com'>Visit W3Schools.com</a>"

    do {

        definition.delegate = self
        definition.editable = false

        let str = try NSAttributedString(data: def.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!, options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)

        let textAttachment = NSTextAttachment()
        textAttachment.image = UIImage(named: "clip_image002.jpg")

        let str2 = NSAttributedString(attachment: textAttachment)

        str.appendAttributedString(str2)

        definition.attributedText = str


    } catch {
        print(error)
    }

基本上str.appendAttributedString(str2)生成錯誤。 我缺少什么?

不允許更改NSAttributedString的內容,必須將要追加的字符串定義為可變的:

let str = NSMutableAttributedString()

NSMutableAttributedString

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM