将 UIColor 应用于 UIImage
通过将 UIColor 应用于 UIImage 实例,使用与多个主题库应用程序相同的 UIImage,如下所示。
// *** Create an UIImage instance with RenderingMode AlwaysTemplate ***
UIImage *imgMenu = [[UIImage imageNamed:@"iconMenu"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
// *** Now Apply `tintColor` to `UIImageView` of UIImageView or UIButton and convert image in given color ***
[btn setImage:imgMenu forState:UIControlStateNormal]; // Set UIImage in UIButton.
[button.imageView setTintColor:[UIColor blueColor]]; // It changes image color of UIButton to blue color
现在假设你想要使用 UIImageView 执行相同操作,然后使用以下代码
[imageView setImage:imgMenu]; // Assign UIImage to UIImageView
[imageView setTintColor:[UIColor greenColor]]; // Change imageview image color to green.
[imageView setTintColor:[UIColor redColor]]; // Change imageview image color to red.