更改 swift 中的图标位置 3

Change icon position in swift 3

我有以下代码在 uilabel 的左侧显示一个图标,我的问题是如何将图标放在 uilabel 的右侧:

let attachment = NSTextAttachment()
attachment.image = UIImage(named: "ic_person")
attachment.bounds = CGRect(x: 0, y: -3, width: 15, height: 15)
let attachmentStr = NSAttributedString(attachment: attachment)
let myString = NSMutableAttributedString(string: "")
myString.append(attachmentStr)
let myString1 = NSMutableAttributedString(string: item_empresa[indexPath.item].nombre_emp!)
myString.append(myString1)
cell.lbl_nombreEmpresa.attributedText = myString

提前致谢

您可以在附加文字后附加附件,将图片放在文字后面

let attachment = NSTextAttachment()
attachment.image = UIImage(named: "ic_person")
attachment.bounds = CGRect(x: 0, y: -3, width: 15, height: 15)

let attributedString = NSMutableAttributedString(string: item_empresa[indexPath.item].nombre_emp ?? "")

attributedString.append(NSAttributedString(attachment: attachment))
cell.lbl_nombreEmpresa.attributedText = attributedString