Swift/기타
[SWIFT]설치된 앱 아이콘 변경하기
삽질중
2023. 5. 17. 12:56
변경할 앱 아이콘 120x120 (icon1@2x.png), 180x180 (icon1@3x.png) 파일을 드래그 해서 Group & Copy 로 프로젝트에 추가한다.
info.plist 파일 속성 추가
- 소스파일로 열어서 추가해도 되고 TARGETS -> Info 에서 하나씩 추가해도 된다.
<key>CFBundleIcons</key>
<dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>icon1</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>icon1</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>icon2</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>icon2</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>icon3</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>icon3</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
</dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string></string>
</array>
<key>CFBundleIconName</key>
<string></string>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
</dict>
변경하기
// 아이콘 변경 가능 여부 판단
if UIApplication.shared.supportsAlternateIcons {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
// 변경할 아이콘 파일 명을 입력 (icon1@3x.png -> icon1)만 입력
UIApplication.shared.setAlternateIconName("icon1", completionHandler: { error in
log(direction: .ERROR, ofType: self, datas: "Icon Change : \(error.debugDescription)")
})
}
}