开发者

Load image and text in one UIWebView

开发者 https://www.devze.com 2023-03-03 01:36 出处:网络
HI guys. I need to load image and text in UIWebView, I loaded image like that NSData *imageData = [[NSData alloc] initWithContentsOfURL:imageUrl];

HI guys. I need to load image and text in UIWebView, I loaded image like that

    NSData *imageData = [[NSData alloc] initWithContentsOfURL:imageUrl];
    [myWebView loadData:imageDa开发者_StackOverflowta MIMEType:@"application/jpg" textEncodingName:nil baseURL:nil];

and text like that

[myWebView loadHTMLString:self.text baseURL:nil];

But when I put it together I see just image, because it is the last in code. How can I load both (image and text) to one UIWebView? Thank you


You can create html-page dynamically and load it into UIWebView:

NSString *imageUrlString = @"http://www.gstatic.com/translate/intl/ru/logo.png";
NSString *yourText = @"Some text here";

NSString *htmlString = [NSString stringWithFormat:@"<img src='%@'/><br><b>%@</b>", imageUrlString, yourText];    
[myWebView loadHTMLString:htmlString baseURL:nil];
0

精彩评论

暂无评论...
验证码 换一张
取 消