gpt4 book ai didi

IOS/objective-C : Change tint of an image view

转载 作者:行者123 更新时间:2023-12-01 19:52:32 25 4
gpt4 key购买 nike

我想在用户触摸它时更改 ImageView 的颜色。我不需要它来改变很多。但是,我希望它变成蓝色。我找到了以下代码来更改渐变,但它没有任何效果。实际上,我不需要渐变,只需要一种色调。将不胜感激任何建议。

 UIView *snapshot = [[UIImageView alloc] initWithImage:image];
snapshot.layer.masksToBounds = NO;
CAGradientLayer *gradient = [CAGradientLayer layer];

gradient.colors = @[(id)[UIColor redColor].CGColor, (id)[UIColor blackColor].CGColor];

[snapshot.layer insertSublayer:gradient atIndex:0];

最佳答案

一种简单且非侵入性的方法是在 ImageView 中添加半透明覆盖。然后可以在按下和释放按钮时显示和隐藏它。

- (void)indicatedImageViewPressed:(UIImageView *)imageView on:(BOOL)on {
UIView *overlay = [imageView viewWithTag:1]; // See if already created
if (overlay == nil) {
overlay = [[UIView alloc] initWithFrame:imageView.bounds];
overlay.tag = 1; // Mark view to find it next time
overlay.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:0.3]; // Your color overlay goes here
[imageView addSubview:overlay];
}
overlay.hidden = !on;
}

关于IOS/objective-C : Change tint of an image view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44979191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com