[英]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.