title: How do I insert an image Inline UILabel in iOS 8 using swift
body: <p>I followed the <a href="https://stackoverflow.com/questions/19318421/how-to-embed-small-icon-in-uilabel">following post</a> on how to use NSTextAttachment to add images inline with your UILabels. I followed the best I could and wrote my version in Swift.</p>
  
  <p>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. </p>
  
  <pre><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;
  </code></pre>