iOS中为网站添加图标到主屏幕以及增加启动画面

iOS中为网站添加图标到主屏幕以及增加启动画面,第1张

概述虽然没有能力开发Native App,但还是可以利用iOS中Safari浏览器的特性小小的折腾一下,做一个伪Web App满足下小小的虚荣心的。 既然是在iOS中的Safari折腾的,那么代码中利用到的也基本上都是Safari的私有属性。 添加图标到主屏幕是Web App的第一步: <link rel="apple-touch-icon-precomposed" sizes="57x57" hre

虽然没有能力开发Native App,但还是可以利用iOS中Safari浏览器的特性小小的折腾一下,做一个伪Web App满足下小小的虚荣心的。

既然是在iOS中的Safari折腾的,那么代码中利用到的也基本上都是Safari的私有属性。

添加图标到主屏幕是Web App的第一步:

<link rel="apple-touch-icon-precomposed" sizes="57x57" href="icon-57.png"><link rel="apple-touch-icon-precomposed" sizes="72x72" href="icon-72.png"><link rel="apple-touch-icon-precomposed" sizes="114x114" href="icon-114.png"><link rel="apple-touch-icon-precomposed" sizes="144x144" href="icon-144.png">


 

添加图标到屏幕里的有两种属性值apple-touch-icon和apple-touch-icon-precomposed,区别就在于是否会应用iOS中自动给图标添加的那层高光。

由于iPhone以及iPad都有两种分辨率的设备存在,图标的尺寸就需要做4个:144×144(iPad Retina)、72×72(iPad)、114×114(iPhone Retina)、57×57(iPhone)。

可以使用sizes尺寸来告诉设备该调用哪个图标。

有了图标还不够像,还需要加上启动画面:

<link rel="apple-touch-startup-image" sizes="2048x1496" href="icon-2048x1496.png" media="screen and (min-device-wIDth: 1025px) and (max-device-wIDth: 2048px) and (orIEntation:landscape) and (-webkit-min-device-pixel-ratio: 2)"><link rel="apple-touch-startup-image" sizes="1536x2008" href="icon-1536x2008.png" media="screen and (min-device-wIDth: 1025px) and (max-device-wIDth: 2048px) and (orIEntation:portrait) and (-webkit-min-device-pixel-ratio: 2)"><link rel="apple-touch-startup-image" sizes="1024x748" href="icon-1024x748.png" media="screen and (min-device-wIDth: 481px) and (max-device-wIDth: 1024px) and (orIEntation:landscape)"><link rel="apple-touch-startup-image" sizes="768x1004" href="icon-768x1004.png" media="screen and (min-device-wIDth: 481px) and (max-device-wIDth: 1024px) and (orIEntation:portrait)"><link rel="apple-touch-startup-image" sizes="640x920" href="icon-640x920.png" media="screen and (max-device-wIDth: 480px) and (-webkit-min-device-pixel-ratio: 2)"><link rel="apple-touch-startup-image" sizes="320x460" href="icon-320x460.png" media="screen and (max-device-wIDth: 320)">


 

apple-touch-startup-image是用来标示启动画面的,但它不像apple-touch-icon可以指定sizes来告诉设备该使用哪个图片(也有一种说法是在iOS5中已经支持sizes识别了,但没有测试成功),所以只能通过media里的设备分辨率的判断值来识别,而iPhone Retina的分辨率值界于取值之间,所以需要通过webkit的私有属性-webkit-min-device-pixel-ratio:2来鉴别像素密度以进行识别。

启动画面的图片尺寸并非完全等于设备的尺寸,比如iPad2的尺寸是1024×768,但它的启动画面尺寸横向是1024×748,竖向尺寸是768×1004,因为需要减去系统状栏的高度20px,而使用的Retina屏幕的iPhone4以及iPad3则需要减去状态栏的高度40px。

Web App运行起来要像Native App,那么就要去掉Safari的一些默认控件,比如地址栏、状态栏之类的。

<Meta name="apple-mobile-web-app-capable" content="yes"><Meta name="apple-mobile-web-app-status-bar-style" content="black"><Meta name="format-detection" content="telephone=no"><Meta name="vIEwport" content="wIDth=device-wIDth,initial-scale=1,minimum-scale=1.0,maximum-scale=1,user-scalable=no">


 

apple-mobile-web-app-capable是用来定义应用全屏展示的;在定义了apple-mobile-web-app-capable的前提下,设置状态栏的属性值apple-mobile-web-app-status-bar-style才有效;format-detection的值用于启用或禁用自动检测在网页中可能出现的电话号码;

vIEwport并非Safari的私有属性,wIDth用于指定宽度,initial-scale指定初始化的缩略比例,minimum-scale指定缩小的比例,而maximum-scale则是放大的比例,当然这些缩放都取决于user-scalable——决定用户是否能缩放页面。

更正:

虽然New iPad采用了Retina屏幕,但实际上物理分辨率并没有变,还是1024*768的,所以以上代码中的New iPad的启动画面代码尺寸有误,应该是

<link rel="apple-touch-startup-image" sizes="2048x1496" href="icon-2048x1496.png" media="screen and (min-device-wIDth:481px) and (max-device-wIDth:1024px) and (orIEntation:landscape) and (-webkit-min-device-pixel-ratio: 2)"><link rel="apple-touch-startup-image" sizes="1536x2008" href="icon-1536x2008.png" media="screen and (min-device-wIDth:481px) and (max-device-wIDth:1024px) and (orIEntation:portrait) and (-webkit-min-device-pixel-ratio: 2)">
总结

以上是内存溢出为你收集整理的iOS中为网站添加图标到主屏幕以及增加启动画面全部内容,希望文章能够帮你解决iOS中为网站添加图标到主屏幕以及增加启动画面所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1090136.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存