【问题标题】:iOS - UIImage tinting highlight always greyiOS - UIImage 着色突出显示始终为灰色
【发布时间】:2015-03-25 12:11:58
【问题描述】:

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

【问题讨论】:

    标签: ios uibutton uiimage highlight tint


    【解决方案1】:

    UIButton有很多状态试试:

    //disable automatically adjust
    self.yourButton.adjustsImageWhenHighlighted = NO;
    
    [self setImage:colorChangedImage forState:UIControlStateHighlighted|UIControlStateSelected];
    

    【讨论】:

    • 谢谢。什么是单 |什么意思?
    • @Dylanthepiguy 这意味着 OR
    猜你喜欢
    • 2022-11-06
    • 1970-01-01
    • 2011-09-08
    • 1970-01-01
    • 2011-12-03
    • 1970-01-01
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    相关资源
    最近更新 更多