UIImage imageNamed requires pathForResource?

前端 未结 4 1379
一向
一向 2020-12-01 08:13

How necessary is it to search for a path to an image using the NSBundle method pathForResource when creating a UIImage using ima

4条回答
  •  难免孤独
    2020-12-01 09:15

    The docs say that “the method looks for an image with the specified name in the application’s main bundle”, so I’d say you can always use just the name. The only exception might be images stored inside subfolders, especially when you have foo/image.png and bar/image.png. I don’t know whether [UIImage imageNamed:@"foo/image"] would work, but it’s trivial to try.

    (What’s a bit confusing in these cases is that the groups in the Xcode tree do not correspond to folders in the resulting app bundle. Their contents are smashed together to the root of the bundle, unless you use a blue folder reference instead of a regular group.)

提交回复
热议问题