0

我有这个按钮,其中背景颜色为白色,图像色调为颜色 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;
    }];
}
4

1 回答 1

0

UIButton has many states try:

//disable automatically adjust
self.yourButton.adjustsImageWhenHighlighted = NO;

[self setImage:colorChangedImage forState:UIControlStateHighlighted|UIControlStateSelected];
于 2015-01-27T02:21:37.513 回答