How to get path of image form Resource of main bundle

前端 未结 3 894
谎友^
谎友^ 2021-01-02 14:04

i have an iPhone application in which i added images directory (Group) in to Resources (group). i want to access that images which is in imag

3条回答
  •  走了就别回头了
    2021-01-02 14:40

    Adding image by following method solved my problem.

    • Right click on project in xcode and select Add Files to "project name".
    • Select your image file from computer local disk.
    • In the pop-up window make sure you select Copy items into destination group's folder and Create Folder References for any added folders and Add to targets.
    • click Add.

    Then with bellow code i can retrieve my image.

    For Objective-C version

    [[NSBundle mainBundle] pathForResource:@"imageName" ofType:@"png"];
    

    For Swift 4.0 version

    Bundle.main.path(forResource: "imageName", ofType: "png")
    

提交回复
热议问题