英文:
Why was the colour of image changed in iOS app?
问题
我遇到了一个奇怪的情况。我的自定义图片在运行的应用程序中的颜色发生了变化! 警报铃的原始颜色如图所示是红色。然而,当应用程序运行时,铃的颜色变成了蓝色!
添加图像的代码如下:
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!
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!
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论