NSTextAttachment を使用して UILabels にインラインで画像を追加する方法については、次の投稿に従いました。私はできる限り最善を尽くし、Swift で自分のバージョンを書きました。
チャット アプリケーションを作成していますが、ビール アイコンを挿入するフィールドで画像が表示されないか、画像がインラインで表示されないようです。エラーは発生しないので、コードに小さな詳細が欠けていると思います。
var beerName:String!
if(sender == bn_beer1)
{
beerName = "beer1.png"
}
if(sender == bn_beer2)
{
beerName = "beer2.png"
}
if(sender == bn_beer3)
{
beerName = "beer3"
}
var attachment:NSTextAttachment = NSTextAttachment()
attachment.image = UIImage(named: beerName)
var attachmentString:NSAttributedString = NSAttributedString(attachment: attachment)
var myString:NSMutableAttributedString = NSMutableAttributedString(string: inputField.text)
myString.appendAttributedString(attachmentString)
inputField.attributedText = myString;