ios - 自上次 Xcode 更新以来,我无法处理图像

标签 ios objective-c xcode

这是我用来将名为“Background.png”的图像添加到 UIImageView 的基本代码:

UIImageView *imageView = [[UIImageView alloc] init];

imageView.image = [UIImage imageNamed:@"Background.png"];

imageView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height);

[self.view addSubview:imageView];

自上次 Xcode 更新后无法加载资源。

我尝试在 iPhone 6 - iOS 10.3 和模拟器 - iOS 11.0 上运行

出于某种原因,即使 iOS 部署目标是版本 10.3,模拟器也可以在 iOS 11.0 上运行

图像在那里,与名为“Background.png”的项目位于同一文件夹中

多年来我一直在做同样的事情,但现在它已经停止工作了。

有人遇到过类似的问题吗?

最佳答案

您可能想利用 Assets.xcassets 的用途。将您的 Assets 放在那里,您就可以轻松地使用您的图像。请注意,您不必输入图像的文件扩展名。很简单,就像这样:

UIImage *markerImage = [UIImage imageNamed:@"marker"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:markerImage];
[imageView setFrame:CGRectMake(0, 0, 100, 100)];
[self.view addSubview:imageView];

我的 Assets.xcassets 中有一张名为 ma​​rker 的图像。

编辑:这是经过测试的,我为这个问题做了一个 Objective-c 项目:)

关于ios - 自上次 Xcode 更新以来,我无法处理图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46380194/

相关文章:

ios - 如何删除我用循环创建的多个按钮?

objective-c - 如何将整数转换为 objective-c 中的相应单词?

python - 是否可以从 ObjC 调用 Python 模块?

xcode - Apple LLVM 编译器 3.1 错误 clang

objective-c - 使用 XIB 文件在 MAC OSX 应用程序中自定义 View

安卓/iOS : Decode polyline string

ios - UIImageview 不会在 super View 中居中

ios - 在不丢失导航栏的情况下呈现第二个 View Controller

objective-c - 在 objective-c 中将NSMutableString转换为NSUrl

ios - TableViewCell 中用于打开 map 应用的按钮