【问题标题】:Accessing the image which is in external bundle访问外部包中的图像
【发布时间】:2023-03-23 13:30:01
【问题描述】:

我创建了一个名为 applausible.bundle 的包,我将包放在了支持文件中。这是我的代码

NSBundle* myBundle;
myBundle = [NSBundle bundleWithPath:@"/Library/applausible.bundle"];
NSString *path = [myBundle pathForResource:@"splash.png" ofType:nil];
[imageName setImage:[UIImage imageNamed:path]];

这里我无法在图像视图上显示图像。我尝试过的另一种方法是在运行应用程序时使用 xib 将图像放置在图像视图上。输出在控制台中是这样的 无法加载从标识符为“com.xxxxxxx.ImageSample”的捆绑包中的笔尖引用的“splash_screen high resolution.png”图像。谁能告诉我哪里出错了。最后我的目标是在外部捆绑包中的UIImageview 上显示图像。

【问题讨论】:

  • 请将您的问题格式化为可读格式。
  • 将日志 stmt 放在 NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"applausible" ofType:@"Bundle"];并在您的图像路径旁边....
  • 捆绑路径显示完美但图片路径为空
  • 图片路径也来了但是图片不显示
  • 如果我的回答对您有帮助,请尝试投票。或在我的答案上添加评论,以便下次改进答案

标签: iphone ios xcode


【解决方案1】:

这可能会对你有所帮助。

    NSString bundlePath = [[NSBundle mainBundle] pathForResource:@"applausible" ofType:@"Bundle"];
NSLog(@"Bundle path is %@",bundlePath);
NSBundle myBundle;
myBundle = [NSBundle bundleWithPath:bundlePath];
NSString *path = [myBundle pathForResource:@"splash_screen high resolution" ofType:@"png"];
UIImage *image=[[UIImage alloc]initWithContentsOfFile:path];
[imageName setImage:image];

请尝试一下。

【讨论】:

    【解决方案2】:

    可能会有帮助

    NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"applausible" ofType:@"Bundle"];
    

    使用此方法,您可以获得捆绑路径。然后使用第二行中的代码

    myBundle = [NSBundle bundleWithPath:bundlePath];
    NSString *path = [myBundle pathForResource:@"splash" ofType:n@"png"];
    [imageName setImage:[UIImage imageNamed:path]];
    

    【讨论】:

    • 非常感谢您的回复。我试过你上面提到的那个,但没有得到结果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 2019-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多