[英]Is it possible to change the app icon while the App is running
不是一個真正重要的問題,但只是好奇。 您可以在運行時更改應用程序圖標嗎? 例如,有一個按鈕,當你按下按鈕時,你會得到一個不同的應用程序圖標(假設應用程序圖標已經“設置”了)。 安卓和iOS。
非常感謝任何輸入。 謝謝
從 iOS 10.3 開始,開發人員能夠以編程方式更改應用程序圖標。
有關詳細信息,您可以參考此鏈接,它顯示了如何動態更改應用程序圖標。
示例代碼:
// change app icon to "Picture A"
@IBAction func pichuButtonDidTap(_ sender: UIButton) {
changeIcon(to: "Picture A")
}
// change app icon to "Picture B"
@IBAction func pikachuButtonDidTap(_ sender: UIButton) {
changeIcon(to: "Picture B")
}
// change app icon to "Picture C"
@IBAction func raichuButtonDidTap(_ sender: UIButton) {
changeIcon(to: "Picture C")
}
func changeIcon(to iconName: String) {
// 1
guard UIApplication.shared.supportsAlternateIcons else {
return
}
// 2
UIApplication.shared.setAlternateIconName(iconName, completionHandler: { (error) in
// 3
if let error = error {
print("App icon failed to change due to \(error.localizedDescription)")
} else {
print("App icon changed successfully")
}
})
}
除非通過軟件升級,否則您無法更改已簽名並密封的 APK 中的清單或資源。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.