How do i insert UIImage on UIWebView

时间秒杀一切 提交于 2020-01-01 15:35:17

问题


I'm trying to display an Animated-GIF image in a UIImageView. Because this way only the first frame is shown i wanted to try a different approach.

UIWebView.

How can i get an Animated-GIF that is in memory (NSData) to display on a UIWebView with all frames..?


回答1:


Thanks Thomas for you response, i don't know if it works because i managed to do it myself now..

Been decoding the GIFs for more then a week now and still with no succes so i went from UIImageView to UIWebView and the following code made it work..

[self.webView loadData:gifData MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];



回答2:


I've not tried it, but something like this :

NSString *html = [NSString stringWithFormat:@"<img src='data:image/gif;base64,%@' />", [myData base64Value];
[myWebView loadHTMLString:html baseURL:nil]

You'll need a NSData category that implements converting to base64, that shouldn't be difficult to find (I've bookmarked http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html)

edit: another way is to decode the gif, so you have an NSArray of the frames : http://pliep.nl/blog/2009/04/iphone_developer_decoding_an_animated_gif_image_in_objc http://blog.stijnspijker.nl/2009/07/animated-and-transparent-gifs-for-iphone-made-easy/



来源:https://stackoverflow.com/questions/4459944/how-do-i-insert-uiimage-on-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!