2012-06-13 50 views
0
我在我的project.Where使用的UIWebView

的框架在web视图中的教改尝试是从HTML数据填补做下面这样的代码:的UIWebView +内容适合的WebView

[webView loadHTMLString:[NSString stringWithFormat:@"<html><body><font face=\"Arial\" size=\"3\"</font>%@</body></html>",[[[dict_Response objectForKey:@"objects"]objectAtIndex:0]objectForKey:@"detaildescription"]] baseURL:[NSURL URLWithString:@"http://newsletter.nobelbiocare.com/"]]; 

现在我设定网页视图的框架: -

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
if(appDel.ori_appDel == UIInterfaceOrientationPortraitUpsideDown || appDel.ori_appDel == UIInterfaceOrientationPortrait) 
     { 
webView.frame=CGRectMake(30,150,710,450); 
}else{ 
webView.frame=CGRectMake(30,150,930,450); 
} 
return yes; 
} 

现在事情发生是在风景模式下的内容在适当的way.But显示当我移动到肖像模式下,它会自动显示水平scrolling.I不想要滚动网页视图中水平模式.. 请帮我..如何解决此问题。

我用了sizetofit和自动尺寸| autofixing。 但后来它也没有解决,请帮助我..

+1

Shweta你可以尝试在'shouldAutorotateToInterfaceOrientation'刷新页面。 –

+0

@InderKumarRathore感谢您的快速回复。但我试图做到这一点,但它没有解决问题。身体标记'%@' –

+1

看跌格式说明不进行任何更改 –

回答

3

@shweta

尝试webViewDidFinishLoad更新您的WebView:这将帮助你。并尝试在html中设置大小而不是Web视图框架。

- (void)webViewDidFinishLoad:(UIWebView *)webview { 
    CGRect oldBounds = [[self webview] bounds]; 
    //in the document you can use your string ... ans set the height 
    CGFloat height = [[webview stringByEvaluatingJavaScriptFromString:@"document.height"] floatValue]; 
    [webview setBounds:CGRectMake(oldBounds.origin.x, oldBounds.origin.y, oldBounds.size.width, height)]; 
} 

主要关心的是该方法。

[webview stringByEvaluatingJavaScriptFromString:@"document.height"] 

通过使用javascript。

+0

的内容没有改变。谢谢你的回复。请给我一个想法如何在HTML中设置大小,而不是webview框架 –

+1

@shweta我已经添加了答案,请使用它... hopw这将为你工作 – Abhishek

+0

@Abhisek感谢webview停止滚动now.But内容被cut.I曾尝试设置内容的大小,但它是创建hte prblem时,ipad从横向移动到纵向,即frame.width 930到710.内容大小仍保持930只在portarait.And它设置manualy内容的web视图的内容被削减。 :(:(请帮助我.. –

1

使用此:

[webView loadHTMLString:[NSString stringWithFormat:@"<html><div style='font-family: arial,helvetica;font-size: 14px;'>%@</div></html>",[[[dict_Response objectForKey:@"objects"]objectAtIndex:0]objectForKey:@"detaildescription"]] baseURL:[NSURL URLWithString:@"http://newsletter.nobelbiocare.com/"]]; 
+0

感谢回答,但不列入影响的WebView的contentsize这得到增加自动旋转ipad时。 –

2

而不是

sizetofitautoresizing|autofixing

webview.scalePageToFit=TRUE

+0

感谢reply.It得到解决我issue.But如果我想在web视图 –

+1

禁用变焦,如果你的问题就解决了,然后继续接受答案的习惯。 – Krunal

+1

禁用变焦试试这个' - (UIView的*)viewForZoomingInScrollView:(UIScrollView的*){滚动视图返回 零; }' – Krunal

1

试试这些
1.将体格标签之间的格式说明符放置为</font>%@</body></html>
2.尝试重新加载网页鉴于此

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    //Reload your web view here 
} 
+0

kumar感谢您的回复。但它不影响webview的内容的格式 –

+0

kumar我正在更新我的问题。我已经格式化了说明符并重新加载了webview。但是webview –