Tunyk Pavel
Tunyk Pavel

Reputation: 2493

Load image and text in one UIWebView

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

    NSData *imageData = [[NSData alloc] initWithContentsOfURL:imageUrl];
    [myWebView loadData:imageData 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

Upvotes: 0

Views: 3181

Answers (1)

5hrp
5hrp

Reputation: 2230

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];

Upvotes: 2

Related Questions