I followed the following post on how to use NSTextAttachment to add images inline with your UILabels. I followed the best I could and wrote my version in Swift.
I am creating a chat application and the field that I'm inserting a beer icon into does not render the image or doesn't seem to render the image inline. I don't get any errors so I'm assuming I'm missing some small little detail in my code.
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;