UIWebView和iPhone 4视网膜显示屏 [英] UIWebView and iPhone 4 retina display
问题描述
我有一个 UIWebView
,它会显示一些本地文本和图像。我在某个地方犯了错误,或者 UIWebView
没有自动处理高分辨率的 @ 2x
后缀图片。
I have a UIWebView
which displays some local text and images. Either I've made a mistake somewhere, or the UIWebView
doesn't automatically handle the @2x
suffix for high resolution images.
所以,我的问题是还有其他人成功将 @ 2x
图片加载到 UIWebView
通过正常的方式,还是我需要做一些特别的事情?我可以以某种方式检测我的用户是否有视网膜显示器吗?
So, my question is has anyone else successfully loaded @2x
images into a UIWebView
through the normal means, or do I need to do something special? Can I somehow detect if my user has a retina display?
推荐答案
根据您的要求......
As per your request...
测试功能。如果你想知道你是否需要显示视网膜图像或常规图像,那么测试你的设备是否有视网膜显示器,而不是特定型号的显示器(未来证明你的应用程序尽你所能,意味着你必须改变当一个新模型出来时,更少的东西)。为此,您可以使用以下示例代码:
Test for functionality. If you want to know if you need to display a retina image or a regular image, then test if your device has a retina display, not that it's of a particular model (future proof your application as best you can, means you have to change less stuff when a new model comes out). To do this, you can use the following sample code:
if([[UIScreen mainScreen] respondsToSelector:@selector(scale)] &&
[[UIScreen mainScreen] scale] == 2.0)
{
/* We have a retina display. */
}
else
{
/* We do not. */
}
这段代码是安全的,截至我写这篇文章的时候,所有型号和所有固件版本。它在将来的版本中也是安全的,直到Apple弃用 scale
方法,这可能永远不会发生。
This code is safe, as of the time I wrote this, on all models and on all firmware versions. It will be safe on future versions as well until Apple deprecates the scale
method, which may never happen.
更多在你的问题上,我不知道如何在webview中做到这一点,而没有预先设置视网膜图像和非视网膜图像的位置。一旦我有了这些信息,我(过去)用它来替换网页希望我替换的一些已知的标记文本,就像在HTML中说的那样: { {{image_location}}}
在哪里我可以下载HTML数据,将其转换为字符串格式,然后替换该字符串替换该文本,如果我们是@ 2x图像的URL在视网膜显示器上,使用适当的比例因子,或者如果没有,则使用正常大小的图像(使用上面的代码)。
More on your question, I don't know how to do that in a webview without having the locations to a retina image and a non-retina image beforehand. Once I have that info, I have (in the past) used it to replace some known sentinel text that the web page expected me to replace, as in I would put something in the HTML that had say: {{{image_location}}}
where I could download the HTML data, get it into string format, then do a replace on that string replacing that text, with the URL of the @2x image if we're on a retina display, with the appropriate scale factor, or the normal sized image if not (using the above code).
希望如果没有人能更好的话,这会有所帮助解决方案。
Hope this helps if nobody comes along with a better solution.
这篇关于UIWebView和iPhone 4视网膜显示屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!