美文网首页
swift 版 富文本图文混排

swift 版 富文本图文混排

作者: 授之以渔不如授之以鱼 | 来源:发表于2021-03-16 10:24 被阅读0次
image.png

大家都是成年人挺忙的,码来!

lazy var specialUITextView: YYTextView = {
        let textView = YYTextView()
        textView.isEditable = false
        textView.isScrollEnabled = false
//        textView.textAlignment = .center
        //创建富文本
        let text = NSMutableAttributedString.init(string: "*由支付宝提供身份认证功能")
        text.yy_font = .systemFont(ofSize: 14)
        text.yy_color = ColorGray5
        text.yy_setColor(.red, range: NSRange(location: 0,length: 1))
        text.yy_alignment = .center
        // 将图片附件转为字符串
        let image = UIImage(named: "icon_zhifubao")
        var attachment: NSMutableAttributedString? = nil
        attachment = NSMutableAttributedString.yy_attachmentString(withContent: image, contentMode: UIView.ContentMode.center, attachmentSize: CGSize(width: 14, height: 14), alignTo: .systemFont(ofSize: 14), alignment: .center)
        //插入图片附件到富文本
        if let attachment = attachment {
            text.insert(attachment, at: 2)
        }
        textView.attributedText = text
        return textView
    }()

相关文章

网友评论

      本文标题:swift 版 富文本图文混排

      本文链接:https://www.haomeiwen.com/subject/yhwrcltx.html