iOS 图文混排 (Swift版)

 // 0> 图片附件

        let attachment = NSTextAttachment()

        

        attachment.image = #imageLiteral(resourceName: "d_aini")

       let height = label.font.lineHeight

        attachment.bounds = CGRect(x: 0, y: -4, width: height, height: height)

       // 1> 属性文本

        let imageStr = AttributedString(attachment: attachment)

        

        // 2> 可变的图文字符串 - NSMutableAttributedString

        let attrStrM = NSMutableAttributedString(string: "")

        attrStrM.append(imageStr)

        attrStrM.append(AttributedString(string: "99!"))

        // 3> 设置 label

        label.attributedText = attrStrM

posted @ 2016-07-10 20:42  _init  阅读(625)  评论(0编辑  收藏  举报