gpt4 book ai didi

iphone - UILabel 文本末尾的 UIImage

转载 作者:行者123 更新时间:2023-12-03 19:23:05 26 4
gpt4 key购买 nike

如果 UILabel 中有超过 1 行文本,如何找到 UILabel 中最后一个字符的坐标?我想在文本末尾添加图像。

enter image description here

最佳答案

我认为您正在寻找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

关于iphone - UILabel 文本末尾的 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3607113/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com