iOS10.3更換App圖標(biāo)
GitHub地址
效果:
Jietu20191025-150526.gif
步驟:
1.確保Assets.xcassets
內(nèi)無任何圖片
15719850866178.jpg
2.將圖標(biāo)拖入項(xiàng)目中之拨,不能使用Assets.xcassets
船老,只能拖入項(xiàng)目宝磨。圖片大小為60的2倍和3倍殿较,即@2x 120*120``@3x 180*180
15719852465125.jpg
3.配置info.plist
箍邮,很容易出錯挠唆,一定要仔細(xì)粹懒,怕出錯可以復(fù)制下面的內(nèi)容,然后替換下圖片名稱。
15719858457694.jpg
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>app_icon_0</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>app_icon_0</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>app_icon_1</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>app_icon_1</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>app_icon_2</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>app_icon_2</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>app_icon_3</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>app_icon_3</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
</dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>app_icon_0</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>UINewsstandIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>app_icon_0</string>
</array>
<key>UINewsstandBindingEdge</key>
<string>UINewsstandBindingEdgeLeft</string>
<key>UINewsstandBindingType</key>
<string>UINewsstandBindingTypeMagazine</string>
</dict>
</dict>
</plist>
4.代碼獲取當(dāng)前圖標(biāo)障贸、更換圖標(biāo)
獲取當(dāng)前圖標(biāo)文件名
if (@available(iOS 10.3, *)) {
NSString *iconName = [UIApplication sharedApplication].alternateIconName;
}
更換圖標(biāo)
if (@available(iOS 10.3, *)) {
if (![[UIApplication sharedApplication] supportsAlternateIcons]) {
return;
}
NSArray *weathers = @[@"app_icon_0", @"app_icon_1", @"app_icon_2", @"app_icon_3"];
NSString *iconName = weathers[sender.selectedSegmentIndex];
[[UIApplication sharedApplication] setAlternateIconName:iconName completionHandler:^(NSError * _Nullable error) {
if (!error) {
return;
}
NSLog(@"更換app圖標(biāo)發(fā)生錯誤了 : %@",error);
}];
}