属性付き文字列の添付ファイルであるテンプレート化された画像の色を設定するにはどうすればよいですか?
バックグラウンド:
UILabel があり、その attributedText を NSAttributedString に設定しています。NSAttributedString には、小さな画像を含む NSTextAttachment が含まれています。画像の色をテキストの色と一致させたいのですが、それを機能させる方法がわかりません。
通常、レンダリング モードを UIImageRenderingModeAlwaysTemplate に設定し、それを含む UIView で tintColor を設定することで、画像に色を付けることが期待されます。UILabel に tintColor を設定しようとしましたが、効果がありません。
これが私のコードです。これは Ruby (RubyMotion) で作成されているため、構文が少しおかしく見えるかもしれませんが、Objective C と 1:1 でマッピングされています。
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 => UIFont.preferredFontForTextStyle(UIFontTextStyleFootnote), NSForegroundColorAttributeName => foreground_color }))
label = UILabel.alloc.initWithFrame(CGRectZero)
label.tintColor = foreground_color
label.attributedText = label_string
label.textAlignment = NSTextAlignmentCenter
label.numberOfLines = 0