tintColor 是一个救星,它将应用主题定制提升到了一个全新的(简单)水平。
//the life saving bit is the new UIImageRenderingModeAlwaysTemplate mode of UIImage
UIImage *templateImage = [[UIImage imageNamed:@"myTemplateImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
imageView.image = templateImage;
//set the desired tintColor
imageView.tintColor = color;
上述代码将根据UIImageview的色调颜色“涂”图像的非透明部分,这很酷。对于像这样简单的东西,不需要核心图形。
我面临的问题是动画。
继续上述代码:
//The array with the names of the images we want to animate
NSArray *imageNames = @[@"1",@"2"@"3"@"4"@"5"];
//The array with the actual images
NSMutableArray *images = [NSMutableArray new];
for (int i = 0; i < imageNames.count; i++)
{
[images addObject:[[UIImage imageNamed:[imageNames objectAtIndex:i]] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
}
//We set the animation images of the UIImageView to the images in the array
imageView.animationImages = images;
//and start animating the animation
[imageView startAnimating];
动画执行正确,但图像使用其原始颜色(即在图形编辑应用程序中使用的颜色)而不是UIImageView的tintColor。我将尝试自己执行动画(通过过度操作,例如循环遍历图像并设置UIImageView的图像属性,并带有NSTimer延迟,以便人眼可以捕捉到它)。
在这样做之前,我想问一下,UIImageView的tintColor属性是否支持我要尝试的这种用途,即用于动画。
谢谢。