Ho seguito il following post su come utilizzare NSTextAttachment per aggiungere immagini in linea con i vostri UILabels. Ho seguito il meglio che potevo e ho scritto la mia versione in Swift.Come inserire un'immagine UILabel in linea in iOS 8 usando swift
Sto creando un'applicazione di chat e il campo in cui inserisco un'icona di birra non esegue il rendering dell'immagine o non sembra rendere l'immagine in linea. Non ho alcun errore quindi presumo che mi manchi qualche piccolo dettaglio nel mio codice.
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;
Qual è la dimensione dell'immagine? – Larme