Xcode 6.3
で検証
xcassets で Render As Template Image
に設定したテンプレート画像を Storyboard 上で UIButton に設定してビルドした時に、iOS 8 だと正しく tintColor が反映されるけど iOS 7 だと tintColor が設定されないという問題がある。たぶん不具合。
UIImageView にいたっては iOS 8 でも tintColor が反映されない。
対処方法としてはコードで画像を設定する。
UIImage *image = [[UIImage imageNamed:@"circle"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; [self.button setImage:image forState:UIControlStateNormal]; self.imageView.image = image;
上記コードで iOS 7 での問題は解消される。
でも iOS 8 の UIImageView では問題が解消されない。
iOS 8 の UIImageView の問題を解消するには tintColor を設定してやる必要がある。
Storyboard 上で現在設定されている tintColor をそのまま設定しても変更が反映されないので、一度 tintColor を nil にしてから再設定する。
iOS 8 では tintColor を設定すれば画像は再設定してやる必要はない。
UIColor *color = self.imageView.tintColor; self.imageView.tintColor = nil; self.imageView.tintColor = color;
これにて対応完了
対応内容をまとめると以下になる。
iOS 7 | iOS 8 | |
---|---|---|
UIButton | コードで画像設定 | 対応不要 |
UIImageView | コードで画像設定 | コードでtintColor設定 |