iOS - UIImage 着色高亮始终为灰色
iOS - UIImage tinting highlight always grey
我有这个按钮,背景颜色是白色,图像色调是颜色 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;
}];
}
UIButton
有很多状态尝试:
//disable automatically adjust
self.yourButton.adjustsImageWhenHighlighted = NO;
[self setImage:colorChangedImage forState:UIControlStateHighlighted|UIControlStateSelected];
我有这个按钮,背景颜色是白色,图像色调是颜色 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;
}];
}
UIButton
有很多状态尝试:
//disable automatically adjust
self.yourButton.adjustsImageWhenHighlighted = NO;
[self setImage:colorChangedImage forState:UIControlStateHighlighted|UIControlStateSelected];