gpt4 book ai didi

ios - 在 iOS 应用程序中显示图像时出现错误

转载 作者:行者123 更新时间:2023-11-28 18:55:19 25 4
gpt4 key购买 nike

我是初学者,在显示图像方面遇到了 iOS 问题。基本上,它不显示任何图像,而只是显示蓝色模糊。我尝试过各种图像以及过去在其他项目中运行良好的图像。因为我是新手,所以我不知道这是否可能是错误或我会在首选项或其他设置问题中更改的内容。为了确保没有其他事情发生,我开始了一个新项目,该项目只有一个 View Controller :

h 文件:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

- (IBAction)Pressed:(id)sender;

@end

文件:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)Pressed:(id)sender {

UIImage *buttonImage = [UIImage imageNamed:@"Image.png"];
[sender setImage:buttonImage forState:UIControlStateNormal];
}
@end

正如我所说,我尝试过 png、jpg、适用于其他项目的图像等。这只是单击按钮时模拟器中发生的情况的几个示例:

apple

banana

只是图像的轮廓,但蓝色。至少可以说这是非常令人沮丧的。我已经尝试过我在这里得到的建议,比如将色调颜色和背景设置为清除,但无济于事。

[sender setTintColor:[UIColor clearColor]];
[sender setBackgroundColor:[UIColor clearColor]];

此外,一开始我认为这可能与我正在从事的项目有关,但它在我开始的任何新项目中都会发生。这可能是一个错误吗?是否值得从头开始重新安装 Xcode? Xcode 有这种错误吗?任何意见表示赞赏。

最佳答案

我想我知道这里发生了什么。转到 Images.xcassets 并点击您遇到问题的图像(即 Image.png)。您会在右侧看到一个名为“渲染为”的选项,如下图所示:

enter image description here

如果此选项设置为“模板图像”,系统将忽略图像的颜色信息并根据图像中的 alpha 值创建图像模板,因此我认为您已设置该选项,因此最好将其更改为“默认”(如我在该示例中所用)或“原始图像”,因此您可以正确看到它。

希望对您有所帮助!

关于ios - 在 iOS 应用程序中显示图像时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34558807/

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