1.创建步骤

  1)MacOS系统下,新建文件夹,修改文件名,放好资源;

  2)修改文件夹后缀为(.bundle);

  3)右键可查看包内容(也可以这时放入资源)。

2.使用

  1)获取自定义的Bundle

1     // 获取自定义的Bundle 两种方式Path和URL均可
2     // 常用Path
3     NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"Demo" ofType:@"bundle"]];
4     // URL
5     NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"Demo" withExtension:@"bundle"]];

  2)获取自定义的Bundle中的资源

1     // 获取image
2     UIImage *image = [UIImage imageWithContentsOfFile:[bundle pathForResource:@"icon_logo" ofType:@"png"]];

3.快捷使用

1     // 常用
2     UIImage *image = [UIImage imageNamed:@"Demo.bundle/icon_logo.png"];

   [UIImage imageNamed:@"xxx.png"]作用范围是[NSBundle mainBundle],用于自定义的Bundle需要使用全路径,相比前面的方式还是比较简便快捷。

相关文章:

  • 2021-09-13
  • 2021-04-22
  • 2022-02-07
  • 2021-12-28
  • 2021-06-13
  • 2022-12-23
  • 2021-04-18
猜你喜欢
  • 2021-06-15
  • 2021-07-19
  • 2022-12-23
  • 2021-05-25
  • 2021-12-29
  • 2021-06-11
  • 2021-04-26
相关资源
相似解决方案