title: How to set color of templated image in NSTextAttachment
body: <p>How can I set the color of a templated image that is an attachment on an attributed string?</p>
  
  <p>Background:</p>
  
  <p>I've got a UILabel and I'm setting its attributedText to an NSAttributedString. The NSAttributedString includes an NSTextAttachment with a small image. Now I want to make my image color match the text color and I can't figure out how to make it work.</p>
  
  <p>I would normally expect to color the image by setting its rendering mode to UIImageRenderingModeAlwaysTemplate and then setting the tintColor on the containing UIView. I've tried setting the tintColor on my UILabel but that has no effect.</p>
  
  <p>Here's my code. It's in Ruby (RubyMotion) so the syntax might look a little funny, but it maps 1:1 with Objective C.</p>
  
  <pre><code>attachment = NSTextAttachment.alloc.initWithData(nil, ofType: nil)
  attachment.image = UIImage.imageNamed(icon_name).imageWithRenderingMode(UIImageRenderingModeAlwaysTemplate)
  
  label_string = NSMutableAttributedString.attributedStringWithAttachment(attachment)
  label_string.appendAttributedString(NSMutableAttributedString.alloc.initWithString('my text', attributes: { NSFontAttributeName =&gt; UIFont.preferredFontForTextStyle(UIFontTextStyleFootnote), NSForegroundColorAttributeName =&gt; foreground_color }))
  
  label = UILabel.alloc.initWithFrame(CGRectZero)
  label.tintColor = foreground_color
  label.attributedText = label_string
  label.textAlignment = NSTextAlignmentCenter
  label.numberOfLines = 0
  </code></pre>