Load app icon from xcassets

前端 未结 3 1361
暖寄归人
暖寄归人 2021-02-02 11:11

I\'d like to display the app icon inside my app. The icon is in the default assets catalog (Images.xcassets).

How do you load it? I tried the following and

3条回答
  •  情话喂你
    2021-02-02 12:00

    I recommend retrieving the icon URL by inspecting the Info.plist since there's no guarantee how the Icon files are named:

    NSDictionary *infoPlist = [[NSBundle mainBundle] infoDictionary];
    NSString *icon = [[infoPlist valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject];
    imageView.image = [UIImage imageNamed:icon]; 
    

    In this case we're fetching the last image URL of the CFBundleIconFiles array. It has the largest resolution. Change this if you need a smaller resolution.

提交回复
热议问题