我有一个用模板矢量图像初始化的UIButton,如下所示:
UIImage *buttonImage = [UIImage imageNamed:@"image_0"];
self.button = [UIButton buttonWithType:UIButtonTypeCustom];
self.button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
[self.button setImage:buttonImage forState:UIControlStateNormal];
self.button.tintColor = [UIColor whiteColor]; // Icon color
通过设置按钮色调,模板图标显示为白色。这就像一个魅力! :)
当发生特定动作时,我希望按钮图像能够生成动画;使用以下方法反复循环显示三个图像:
- (void)startAnimating {
if (![self.button.imageView isAnimating]) {
UIImage *buttonImage1 = [UIImage imageNamed:@"image_1"];
UIImage *buttonImage2 = [UIImage imageNamed:@"image_2"];
UIImage *buttonImage3 = [UIImage imageNamed:@"image_3"];
self.button.imageView.animationImages = @[buttonImage1,buttonImage2,buttonImage3];
//self.button.imageView.tintColor = [UIColor whiteColor];
self.button.imageView.animationDuration = 1;
[self.button.imageView startAnimating];
}
}
问题是动画图像全部为黑色(如模板矢量图像),而不是预期的白色。
即使添加了注释行,图像仍为黑色。关于我可以尝试做什么以保持所有图像始终保持白色的任何想法?
提前谢谢你, 安德斯