加载内容时更改 UIWebView 的颜色
我的应用程序中有一个 UIWebView,它显示一些 html 格式的文本(从我的包中的 .plist 文件加载)。 UIWebView 大约需要 1 秒才能在屏幕上呈现文本,在此期间整个 UIWebView 呈白色。我尝试将视图的背景颜色设置为“透明”或“黑色”,但这没有任何作用。我还尝试使用委托方法仅在 didLoadContent
时显示 UIWebView,但该方法从未被调用,因为我们不涉及任何请求,我只在那里渲染一个 html 字符串。
有没有办法在视图渲染之前不显示任何内容?
如果没有,是否有另一种方法可以在 iPhone 上呈现 html 文本?
谢谢。
I have a UIWebView in my app that shows some html-formatted text (loaded from a .plist file from my bundle). The UIWebView takes about 1 second to render the text on the screen and during that second the whole UIWebView is white. I have tried setting the backgronud color of the view to clear
or black
but that did not do anything. I also tried using the delegate methods to show the UIWebView only when it didLoadContent
but that method is never called since there us no request involved, I'm only rendering an html string there.
Is there a way to show nothing until the view is rendered?
If not, is there another way to render html-text on an iPhone?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的脑海中浮现出:
将 UIWebView 的
hidden
属性设置为 YES,显示一些内容,调用选择器在 2-3 秒内将隐藏属性更改为 NO。顺便说一句,你的意思是你正在加载本地 HTML 文件吗?或者是下载文件造成的延迟?
〜纳塔纳夫拉。
Off the top of my mind:
Set the UIWebView's
hidden
property to YES, display something call a selector to change the hidden property to NO in 2-3 seconds.BTW do you mean you're loading a local HTML file? Or is the delay created by downloading the file?
~ Natanavra.
你说这个 HTML 是在“应用程序加载时”加载和呈现的,我猜这意味着启动而不是从某个地方加载其他数据?我还猜测 HTML 是完全静态的硬编码数据,因为您从 .plist“离线”加载它...
建议:为什么不截取已渲染页面的屏幕截图,将其保存在您的应用程序中并在应用程序启动期间显示?应该更快。
You said this HTML was loaded and presented "while app loads" which I guess means starting up instead of loading some other data from somewhere? I'm also guessing the HTML is fully static hardcoded data, since you load it "offline" from .plist...
Suggestion: why don't you take a screenshot of the ready-rendered page, save that inside your app and display during app startup? Should be faster.
我在我的应用程序中使用一个 javascript 变量来处理这个问题,我使用每 0.5 秒触发一次的 NSTimer 检查该变量...我将视图隐藏起来,直到设置该变量...
I handle this in my app with a javascript variable that I check with a NSTimer that is fired every 0.5 seconds... I leave the view hidden until that variable is set...