How iOS adds icon replacement in your app

Source: Internet
Author: User

First, set the icon information in the Info.plist

First, the icons that need to be replaced are declared in the following way so that we can call the files and methods normally. Note that the icon name and the corresponding file name of each icon correspond to each other.

Second, add the icon file in the project root directory

The icon file needs to be added under the root directory for normal invocation. Note that the icons are available in 2x and 3x sizes of two 120x120 and 180x180 respectively.

Of course Assets also to add, in order to facilitate the use of preview in the application.

Iii. Call the replacement function where it is used

The final step is actually very simple, in the need to call the place changeIcon(iconName:String?) , parameters for us to add a good app icon name. In the changeIcon(iconName:String?) need to determine whether to support the replacement of icons, so as to avoid errors, of course, can also be judged in advance to show or hide the feature.

func changeIcon(iconName:String?) {        if #available(iOS 10.3, *) {            if UIApplication.shared.supportsAlternateIcons {//判断设备是否支持更换图标                print("支持更换图标!")                //开始更换                UIApplication.shared.setAlternateIconName(iconName, completionHandler: { (error) in                    if error != nil {                        print("替换icon失败\(String(describing: error?.localizedDescription))")                    }                })            }else {                print("设备不支持更换图标")            }        } else {            // Fallback on earlier versions        }    }

 https://github.com/bjdehang/OneSwift/blob/master/5.%E5%A6%82%E4%BD%95%E5%9C%A8%E5%BA%94%E7%94%A8%E4%B8%AD%E6%B7%BB%E5%8A%A0%E5%9B%BE%E6%A0%87%E6%9B%B4%E6%8D%A2%E5%8A%9F%E8%83%BD.md

How iOS adds icon replacement in your app

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.