2013-02-02 55 views
0

我正在制作一个应用程序,我从Web服务中获取一些html数据,并在UIWebView中显示该数据。我已经修复了UIWebView“310”的宽度,但是有些时候数据不在这个帧中,数据从边缘切出。我从网络接收该数据 -如何根据宽度调整UIWebView的所有内容?

的NSString * resul = @ “<div align=\"left\">As stated Please give a&nbsp;chance&nbsp;to serve you.<br></div><div align=\"left\"><br></div><div align=\"left\"><div class=\"lc\" style=\"margin: 0px; font-size: 11px; font-family: Arial, Helvetica, sans; clear: left; float: left;宽度:348px;text-align: center;\"><p style=\"text-align: justify; line-height: 14px; margin: 0px 0px 14px; padding: 0px;\"><strong>Lorem Ipsum</strong>&nbsp;is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p></div><div class=\"rc\" style=\"margin: 0px; font-size: 11px; font-family: Arial, Helvetica, sans; clear: right; float: right;宽度:348px;text-align: center;\"><h2 class=\"why\" style=\"margin: 0px; padding: 0px; font-weight: normal; font-size: 12px; height: 26px; text-align: left; background-image: url(http://www.lipsum.com/images/en/heading.gif); background-position: 0px -52px; background-repeat: no-repeat no-repeat;\"></h2><p style=\"text-align: justify; line-height: 14px; margin: 0px 0px 14px; padding: 0px;\">It is a long ehat a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p></div></div>

我知道其中的原因我收到了大小348从网页。所以我想问一下如何根据我们的框架大小调整它。我用 -

webview.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
webview.scalesPageToFit = YES; 
webview.autoresizesSubviews=YES; 

但数据显示在这么小的尺寸[1]

[数据在显示小图]和我也用委托方法webViewDidFinishLoad但没有得到正确的格式。!。

回答

0

您可以编辑“resul”字符串....我的意思是只更改“宽度:348px;”到“width:310px;”

试试这个:

NSString *str1 = [[NSString alloc] initWithFormat:@"width: 348px;"]; 
NSString *str2 = [[NSString alloc] initWithFormat:@"width: 310px;"]; 
NSRange indexrange = [resul rangeOfString:str1]; 
while (indexrange.length !=0) { 
    [resul replaceCharactersInRange:indexrange withString:str2]; 
    indexrange = [resul rangeOfString:str1]; 
} 
+0

感谢您的回复,这不是永久的解决方案。形式网页结束它可能会有所不同宽度:320像素或宽度:400像素。 –

+0

抱歉,对于迟到的答案.....我刚刚发现了一种方法根据帧的宽度..... 只需将str2从“宽度:348px”更改为“宽度:100%”...它会填满整个框架。 – NULL

0

我也有类似的问题。这是我的解决方案(这也包括方向变化):

float portraitRatio; 

在 - (空)webViewDidFinishLoad:(UIWebView的*)theWebView补充:

UIScrollView *scroll = theWebView.scrollView; 
scroll.scrollEnabled = YES; 
portraitRatio = theWebView.bounds.size.width/scroll.contentSize.width; 
[self resizeOnOrientationChanged]; 


- (void) resizeOnOrientationChanged 
{ 
float zoom; 
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) { 
    //iPhone 
    for (UIWebView *aWebView in openWebViewsArray) { 

     [aWebView setFrame:CGRectMake(0, 30, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-30)]; 
     if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) { 
      zoom = aWebView.bounds.size.width/[webView scrollView].contentSize.width; 
     } 
     else { 
      zoom = portraitRatio; 
     } 
     NSString *jsCommand = [NSString stringWithFormat:@"document.body.style.zoom = %f;",zoom]; 
     [aWebView stringByEvaluatingJavaScriptFromString:jsCommand]; 
    } 
    [self.webView setFrame:CGRectMake(0, 30, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-30)]; 
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) { 
     zoom = self.webView.bounds.size.width/[self.webView scrollView].contentSize.width; 
    } 
    else { 
     zoom = portraitRatio; 
    } 
    NSString *jsCommand = [NSString stringWithFormat:@"document.body.style.zoom = %f;",zoom]; 
    [self.webView stringByEvaluatingJavaScriptFromString:jsCommand]; 
} 
else { 
    for (UIWebView *aWebView in openWebViewsArray) { 

     [aWebView setFrame:CGRectMake(0, 60, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-60)]; 
     if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) { 
      zoom = aWebView.bounds.size.width/[webView scrollView].contentSize.width; 
     } 
     else { 
      zoom = portraitRatio; 
     } 
     NSString *jsCommand = [NSString stringWithFormat:@"document.body.style.zoom = %f;",zoom]; 
     [aWebView stringByEvaluatingJavaScriptFromString:jsCommand]; 
    } 
    [self.webView setFrame:CGRectMake(0, 60, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-60)]; 
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) { 
     zoom = self.webView.bounds.size.width/[self.webView scrollView].contentSize.width; 
    } 
    else { 
     zoom = portraitRatio; 
    } 
    NSString *jsCommand = [NSString stringWithFormat:@"document.body.style.zoom = %f;",zoom]; 
    [self.webView stringByEvaluatingJavaScriptFromString:jsCommand]; 
} 

}

相关问题