如何将图片添加到<p>
标记中?在我的html数据中有多个<p>
标记。那么如何设置不同的图像来添加和使用UIWebView.Thanks in Advance
答案 0 :(得分:1)
在HTML中添加图片:
<p><img src="yourawesomeimage.png" alt="Awesome!" /></p>
将HTML添加到UIWebView:
NSString* htmlContent = @"<html><head><title></title></head><body><p><img src='image.jpg' /></p></body></html>";
[self.webView loadHTMLString:htmlContent baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
答案 1 :(得分:1)
你可以这样做:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"file:/%@//",imagePath]];
NSString *htmlString = @"<p> <img src=\"sample.jpg\" width=\"50\" height=\"50\"/>";
[webView loadHTMLString:htmlString
baseURL:url];
答案 2 :(得分:1)
添加此代码以查看控制器
- (void)viewDidLoad
{
[super viewDidLoad];
[self redrawDesing];
NSURL *htmlFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"legal" ofType:@"html"] isDirectory:NO];
[contentView loadRequest:[NSURLRequest requestWithURL:htmlFile]];
[contentView setScalesPageToFit:YES];
contentView.delegate=self;
[contentView setDelegate:self];
}
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeLinkClicked ) {
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}
p.s replace&#34; legal&#34;使用此部分中的html文件名 NSURL * htmlFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@&#34; legal&#34; ofType:@&#34; html&#34;] isDirectory:NO];