简体   繁体   English

iOS 应用问题 - 无法从图像资产目录访问图像

[英]iOS App Issue - Can't access image from image asset catalog

I'm new to iOS development, so apologies for advance.我是 iOS 开发的新手,所以提前道歉。 I know this has been covered earlier but I can't seem to find anything that helps with my issue.我知道这已经在前面讨论过,但我似乎找不到任何有助于解决我的问题的东西。

Its a fairly simple but annoying issue.这是一个相当简单但令人讨厌的问题。

I have a image in assets with a file name of hollwood.png but a xcode name, "hollywood" (no png).我在资产中有一个图像,文件名为 hollwood.png,但 xcode 名称为“hollywood”(无 png)。

I am trying to set a UIImageView to display it.我正在尝试设置一个 UIImageView 来显示它。

So in ViewDidLoad I have the following: (imageContainer is the UIImageView IBOutlet)所以在 ViewDidLoad 我有以下内容:(imageContainer 是 UIImageView IBOutlet)

- (void)viewDidLoad {
super viewDidLoad];

self.model = [Model sharedModel]; 

self.imageContainer.image = [UIImage imageNamed:@"hollywood"];

} 

I can not get it to display the image from Assets.我无法让它显示资产中的图像。
I know the UIImageView outlet works correctly because I can have the app choose a photo from gallery and set the photo to UIImageView .我知道UIImageView插座工作正常,因为我可以让应用程序从图库中选择一张照片并将照片设置为UIImageView

I'm having a very difficult time figuring out how to load the image I saved in the assets catalog into UIImageView .我很难弄清楚如何将我保存在资产目录中的图像加载到UIImageView

I just had this issue.我刚刚有这个问题。 I had dragged the image and for some reason Xcode added a weird "Design" locale and I couldn't load the image using UIImage(named: ).我拖动了图像,出于某种原因,Xcode 添加了一个奇怪的“设计”语言环境,我无法使用 UIImage(named: ) 加载图像。 I don't know if this is your case, but you can try right clicking on the image in the Asset Catalog, "Show in Finder", opening the folder and checking the "Contents.json" file.我不知道这是否是您的情况,但您可以尝试右键单击资产目录中的图像,“在 Finder 中显示”,打开文件夹并检查“Contents.json”文件。 Each image there should only have the keys "idiom", "filename" and "scale".那里的每个图像应该只有键“惯用语”、“文件名”和“比例”。

Make sure your image is added in Compile Sources确保您的图像已添加到编译源中

AppTarget->Build Phases-> Compile Sources AppTarget->Build Phases-> Compile Sources

If not try to add that and check.如果没有尝试添加并检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从其他资产目录加载图像 - Can't load image from other asset catalog 使用静态图片作为Asset Catalog中的启动图片iOS 9 - Use static image for launch image iOS 9 from Asset Catalog 带有iOS 8 Universal应用程序的资产目录和大小调整类的图像大小? - Image sizes with Asset Catalog and Sizing Classes for a iOS 8 Universal app? Xamarin iOS启动屏幕图像在故事板中不从资产目录拉出 - Xamarin iOS Launch Screen Image In Storyboard Not Pulling From Asset Catalog iOS:资产目录中启动图像上的黑线 - iOS: black line on Launch Image from asset catalog 如何从 UIWebView(或 WKWebView)访问资产目录中的图像资源 - How to access image resource in asset catalog from UIWebView (or WKWebView) iOS 8资产目录图像大小令人困惑 - IOS 8 asset catalog image sizes confusing 使用资产目录特权从 URL 下载图像 - Downloading an image from URL with Asset Catalog perks 除了启动图像和应用程序图标,我可以使用资产目录来管理图像吗? - can I use asset catalog to manage image other than launch image and app icon? 带有资产目录的iOS图像切片会创建奇怪的工件 - iOS image slicing with asset catalog creates strange artifacts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM