我有这个按钮,背景颜色为白色,图像色调为颜色x。选择后,我希望颜色交换 - bg是x(我可以轻松做到),但图像色调总是灰色(或我设置的颜色的深色版本)。我怎样才能改变它?
UIImage *image = [UIImage imageNamed:@"House"];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[self setImage:image forState:UIControlStateNormal];
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
//
- (void)highlight {
[super highlight];
[UIView animateWithDuration:HIGHLIGHT_ANIMATION_TIME animations:^{
self.tintColor = [UIColor whiteColor];
}];
}
- (void)unhighlight {
[super unhighlight];
[UIView animateWithDuration:HIGHLIGHT_ANIMATION_TIME animations:^{
self.tintColor = self.colour;
}];
}
答案 0 :(得分:0)
UIButton
有许多州尝试:
//disable automatically adjust
self.yourButton.adjustsImageWhenHighlighted = NO;
[self setImage:colorChangedImage forState:UIControlStateHighlighted|UIControlStateSelected];