欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Swift簡單快速的動態(tài)更換app圖標(biāo)AppIcon方法示例

 更新時間:2023年06月12日 11:30:54   作者:山水域  
這篇文章主要為大家介紹了Swift動態(tài)更換app圖標(biāo)AppIcon的簡單快速方法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

關(guān)鍵方法

  • 獲取到當(dāng)前AppIcon的名稱
 // 獲取到當(dāng)前AppIcon的名稱
let iconName = UIApplication.shared.alternateIconName 
  • 是否支持切換APPIcon圖
 // 是否支持切換APPIcon圖
if UIApplication.shared.supportsAlternateIcons {
}
  • 切換APPIcon圖方法
 // 切換APPIcon圖方法 參數(shù)填寫是AppIcon的名稱(Assets 中的圖片名稱)
        UIApplication.shared.setAlternateIconName("AppIcon 1") { err in
            if err == nil {
                //成功了,跳轉(zhuǎn)到成功報告頁
            }
        }

具體代碼及UI

頁面UI例圖

class MCAppIconVC: UIViewController {
    var selectInt = 1
    override func viewDidLoad() {
        super.viewDidLoad()
        // 獲取到當(dāng)前AppIcon的名稱
        let iconName = UIApplication.shared.alternateIconName 
        if let tagStr = iconName?.replacingOccurrences(of: "AppIcon ", with: "") {// 因為我設(shè)置的APPIcon名稱是"AppIcon 1", "AppIcon 2"等 這樣可以獲取后面的數(shù)字 布局UI
            let tag = Int(tagStr) ?? 1
            for i in 11...14 {
                if let imageView = self.view.viewWithTag(i) as? UIImageView {// 所有按鈕設(shè)置未未選中
                    imageView.image = UIImage(named: "btn_normal_icon")
                }
            }
            if let imageView = self.view.viewWithTag(10+tag) as? UIImageView {// 設(shè)置選中的UI
                imageView.image = UIImage(named: "btn_npresses_icon")
            }
            selectInt = tag // 記錄當(dāng)前選中的是哪個
        }
        // Do any additional setup after loading the view.
    }
   //    @IBAction func tapGesture(_ sender: UITapGestureRecognizer) {
//        let tag = sender.view?.tag ?? 1
//        for i in 11...14 {
//            if let imageView = self.view.viewWithTag(i) as? UIImageView {
//                imageView.image = UIImage(named: "btn_normal_icon")
//            }
//            if let view = self.view.viewWithTag(i-10) {
//                view.layer.cornerRadius = 16
//                view.layer.masksToBounds = true
//                view.layer.borderColor = UIColor.white.cgColor
//                view.layer.borderWidth = 2
//            }
//        }
//        if let imageView = self.view.viewWithTag(10+tag) as? UIImageView {
//            imageView.image = UIImage(named: "btn_npresses_icon")
//        }
//        if let view = self.view.viewWithTag(tag) {
//            view.layer.cornerRadius = 16
//            view.layer.masksToBounds = true
//            view.layer.borderColor = UIColor(named: "ThemeYellow")?.cgColor
//            view.layer.borderWidth = 2
//        }
//        selectInt = tag
//    }
    @IBAction func setupBtnAction(_ sender: UIButton) { //點擊下面的按鈕
        if UIApplication.shared.supportsAlternateIcons { //是否支持切換APPIcon圖
            if let iconName = UIApplication.shared.alternateIconName, iconName != "AppIcon \(selectInt)" {
                UIApplication.shared.setAlternateIconName("AppIcon \(selectInt)") { err in
                    if let err = err {
                    }else {
                        //成功了,跳轉(zhuǎn)到成功報告頁
                    }
                }
            }else if UIApplication.shared.alternateIconName == nil, selectInt != 1 {
                UIApplication.shared.setAlternateIconName("AppIcon \(selectInt)") { err in
                    if let err = err {
                    }else {
                         //成功了,跳轉(zhuǎn)到成功報告頁
                    }
                }
            }
        }
    }
}

Assets 圖片設(shè)置 APPIcon名稱與上面的要一致

AppIcon 文件配置

以上就是Swift簡單快速的動態(tài)更換app圖標(biāo)AppIcon方法示例的詳細(xì)內(nèi)容,更多關(guān)于Swift 動態(tài)更換app圖標(biāo)-AppIcon的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Swift中動態(tài)調(diào)用實例方法介紹

    Swift中動態(tài)調(diào)用實例方法介紹

    這篇文章主要介紹了Swift中動態(tài)調(diào)用實例方法介紹,在Swift中有一類很有意思的寫法,可以讓我們不直接使用實例來調(diào)用這個實例上的方法,而是通過類型取出這個類型的某個實例方法的簽名,然后再通過傳遞實例來拿到實際需要調(diào)用的方法,需要的朋友可以參考下
    2015-01-01
  • 簡單分析Swift語言的一些基本特征

    簡單分析Swift語言的一些基本特征

    這篇文章主要介紹了Swift語言的一些基本特征,本文從各語言最基礎(chǔ)的類與對象等方面來講,需要的朋友可以參考下
    2015-07-07
  • 深入淺出的聊聊Swift高階函數(shù)

    深入淺出的聊聊Swift高階函數(shù)

    函數(shù)式編程就是高階函數(shù)編程的應(yīng)用,所以要熟練掌握基礎(chǔ)的高階函數(shù)是必須的filter、map、reduce、flatmap就是必備的高階函數(shù),這篇文章主要給大家介紹了關(guān)于Swift高階函數(shù)的相關(guān)資料,需要的朋友可以參考下
    2021-09-09
  • swift中可選值?和!使用的方法示例

    swift中可選值?和!使用的方法示例

    這篇文章主要給大家介紹了關(guān)于swift中可選值?和!使用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • Swift中類與結(jié)構(gòu)的初始化示例解析

    Swift中類與結(jié)構(gòu)的初始化示例解析

    這篇文章主要為大家介紹了Swift中類與結(jié)構(gòu)的初始化解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪
    2022-03-03
  • swift中defer的實際應(yīng)用小結(jié)

    swift中defer的實際應(yīng)用小結(jié)

    這篇文章主要給大家介紹了關(guān)于swift中defer的實際應(yīng)用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • Swift繪制漸變色的方法

    Swift繪制漸變色的方法

    這篇文章主要為大家詳細(xì)介紹了Swift繪制漸變色的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • RxSwift實現(xiàn)替換delegate的方法示例

    RxSwift實現(xiàn)替換delegate的方法示例

    這篇文章主要給大家介紹了關(guān)于RxSwift實現(xiàn)替換delegate的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用RxSwift具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • Swift?reduce函數(shù)使用示例詳解

    Swift?reduce函數(shù)使用示例詳解

    這篇文章主要為大家介紹了Swift?reduce函數(shù)使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • Swift之UITabBarController 導(dǎo)航控制器的自定義

    Swift之UITabBarController 導(dǎo)航控制器的自定義

    本文給大家介紹swift導(dǎo)航控制器之UITabBarController,本文通過代碼實例給大家講解swift導(dǎo)航控制器,導(dǎo)航控制器類繼承UITabBarController,代碼簡單易懂,需要的朋友可以參考下
    2015-10-10

最新評論