UILabel文本末尾的UIImage [英] UIImage in the end of UILabel text
本文介绍了UILabel文本末尾的UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我们有多于1行的文本,如何在UILabel中找到最后一个字符的坐标?
我想在文本末尾添加图片。
how to find coordinate of the last character in UILabel if we have more then 1 line of text in it? I would like to add an image in the end of the text.
推荐答案
我认为您正在寻找 NSTextAttachment
// create an NSMutableAttributedString
let fullString = NSMutableAttributedString(string: "Your text")
// create our NSTextAttachment
let imageAttachment = NSTextAttachment()
imageAttachment.image = UIImage(named: "icon")
// wrap the attachment in its own attributed string so we can append it
let imageString = NSAttributedString(attachment: imageAttachment)
// add the NSTextAttachment wrapper to our full string, then add some more text.
fullString.append(imageString)
// draw the result in a label
yourLabel.attributedText = fullString
这篇关于UILabel文本末尾的UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文