我正在创建一个应用程序,其中我从Web服务获取一些HTML数据,我在UIWebView中显示该数据。我已经修复了UIWebView“310”的宽度,但是有些时间数据没有出现在这个框架中,数据是从边缘切出的。我从网上收到这些数据 -
NSString * resul = @“<div align=\"left\">As stated Please give a chance 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> 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 :(得分:0)
你可以编辑“结果”字符串......我的意思是改变“宽度:348px;”到“宽度: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];
}
答案 1 :(得分:0)
我有类似的问题。这是我的解决方案(它还包括方向更改):
float portraitRatio;
in - (void)webViewDidFinishLoad:(UIWebView *)theWebView add:
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];
}
}