为什么在iOS应用中更改了图像的颜色?

huangapple go评论64阅读模式
英文:

Why was the colour of image changed in iOS app?

问题

我遇到了一个奇怪的情况。我的自定义图片在运行的应用程序中的颜色发生了变化!为什么在iOS应用中更改了图像的颜色? 警报铃的原始颜色如图所示是红色。然而,当应用程序运行时,铃的颜色变成了蓝色!为什么在iOS应用中更改了图像的颜色?

添加图像的代码如下:

UIImage *alertImage = [UIImage imageNamed:@"alert_bell"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:alertImage];
[imageView setBackgroundColor:[UIColor redColor]];
UIGestureRecognizer *tapGR = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(disruptionsAlertAction:)];
[self.view addGestureRecognizer:tapGR];
cell.accessoryView = imageView; // cell 是一个 TableViewCell

我不知道是什么改变了铃的颜色以及如何修复它。

如果有人能解释一下并告诉我如何修复,我将不胜感激!非常感谢!

英文:

I encountered a weird thing. The colour of my custom image was changed in the running app!
为什么在iOS应用中更改了图像的颜色? The original colour of the alert bell image is red as shown. However, when the app runs, the colour of that bell changes to blue! 为什么在iOS应用中更改了图像的颜色?

The code to add the image is as follows:

UIImage *alertImage = [UIImage imageNamed:@"alert_bell"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:alertImage];
[imageView setBackgroundColor:[UIColor redColor]];
UIGestureRecognizer *tapGR = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(disruptionsAlertAction:)];
[self.view addGestureRecognizer:tapGR];
cell.accessoryView = imageView; // cell is a TableViewCell

I have idea what changed the colour if the bell and how to fix.

I would very much appreciate it if anyone can please explain this and let me know how I can fix it. Heaps of thanks!

答案1

得分: 1

我认为你需要将图像视图的渲染模式设置为 **"UIImageRenderingModeAlwaysOriginal"**

    UIImage *myIcon = [[UIImage imageNamed:@"alert_bell"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImageView *myImageView = [[UIImageView alloc] initWithImage:myIcon];

这可能会解决你的问题。
英文:

I think you need to set the rendering mode of the image view as "UIImageRenderingModeAlwaysOriginal"

UIImage *myIcon = [[UIImage imageNamed:@"alert_bell"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImageView *myImageView = [[UIImageView alloc] initWithImage:myIcon];

This could solve your issue.

huangapple
  • 本文由 发表于 2023年4月6日 20:25:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75949482.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定