码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 图文混排 (Swift版)

时间:2016-07-10 21:49:05      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:

 // 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

iOS 图文混排 (Swift版)

标签:

原文地址:http://www.cnblogs.com/kingtoKing/p/5658512.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!