以前我們用過favicon在瀏覽器給網站進行身份標識,用法如下:
<link rel="shortcut icon" />
<link rel="Bookmark" />
現今移動設備越來越多,蘋果為iOS設備配備了apple-touch-icon私有屬性,添加該屬性,在iPhone,iPad,iTouch的safari瀏覽器上可以使用添加到主屏按鈕將網站添加到主屏幕上,方便用戶以后訪問。實現方法是在HTML文檔的<head>標簽加入下面代碼即可
<link rel="apple-touch-icon" href="/custom_icon.png"/>
apple-touch-icon 標簽支持sizes屬性,可以用來放置對應不同的設備。
57×57(默認值)的圖標對應320×640的iphone老設備,72×72對應ipad,114×114對應retina屏的iPhone及iTouch。ipad3對應144×144的高分辨率。
這是官方開發社區的詳細介紹:
Create different sizes of your app icon for different devices. If you’re creating a universal app, you need to supply app icons in all four sizes.
For iPhone and iPod touch both of these sizes are required:
57 x 57 pixels
114 x 114 pixels (high resolution)
For iPad, both of these sizes are required:
72 x 72 pixels
144 x 144 (high resolution)
When iOS displays your app icon on the Home screen of a device, it automatically adds some visual effects to your icon so that it coordinates with the built-in icons on the Home screen. Specifically, iOS adds:
Rounded corners
Drop shadow
Reflective shine (unless you prevent the shine effect)
Note: You can prevent the addition of all effects by naming your icon apple-touch-icon-precomposed.png (this is available in iOS 2 and later).
Ensure your icon is eligible for the visual enhancements iOS adds (if you want them). You should produce an image in PNG format that:
Has 90° corners
Does not have any shine or gloss
所以最完善的寫法應該是:
<link rel="apple-touch-icon" sizes="57x57" href="touch-icon-iphone.png" />
<link rel="apple-touch-icon" sizes="72x72" href="touch-icon-ipad.png" />
<link rel="apple-touch-icon" sizes="114x114" href="touch-icon-iphone4.png" />
<link rel="apple-touch-icon" sizes="144x144" href="apple-touch-icon-ipad3-144.png" />
雖然官方都用的png圖片做說明,但實際測試jpg格式也可用(不推薦),圖片無需做圓角和高光效果,同Native App一樣,系統會自動為圖標添加圓角及高光。如果不想系統對圖標添加效果,可以用apple-touch-icon-precomposed代替apple-touch-icon,這時我們提供的圖標就要自己做圓角和高亮效果了。
圖標搜索的優先級如下:
如果沒有跟相應設備推薦尺寸一致的圖標,那個會優先使用比推薦尺寸大,但最接近推薦尺寸的圖標。
如果沒有比推薦尺寸大的圖標,會優先選擇最接近推薦尺寸的圖標。
如些有多個圖標符合推薦尺寸,會優先選擇包含關鍵字precomposed的圖標。
如果未在區域指定用link標簽指定圖標,會自動搜索網站根目錄下有apple-touch-icon...或者 apple-touch-icon-precomposed…前綴的圖標。 如設備推薦尺寸為57x57,優先級如下:
apple-touch-icon-57×57-precomposed.png
apple-touch-icon-57×57.png
apple-touch-icon-precomposed.png
apple-touch-icon.png
在第三代 iPad 上有四種圖標規格: 57x57, 72x72, 114x114, 144x144.
由于 retina 圖標的尺寸是標準圖標大小的2倍,因此實際上我們只需要只做2款圖標即可:114 x 114 和 144 x 144 。 將retina 圖標的大小設置成標準圖標的尺寸,那么IOS就會根據情況自動進行縮放了。
<link rel="apple-touch-icon" sizes="57x57" href="touch-icon-iphone-114.png" />
<link rel="apple-touch-icon" sizes="114x114" href="touch-icon-iphone-114.png" />
<link rel="apple-touch-icon" sizes="72x72" href="touch-icon-ipad-144.png" />
<link rel="apple-touch-icon" sizes="144x144" href="touch-icon-ipad-144.png" />
備注:以上轉載自關于Apple設備私有的apple-touch-icon屬性詳解
由于文章發表時間的關系,已通過查詢Xcode的icon獲知,新的App icon應是如下圖
其中App的規格為60pt的2倍及3倍,即為120pt和180pt