Objective-C - 找到UIWebView错误?

时间:2011-10-20 14:37:50

标签: objective-c cocoa-touch uiwebview

我将UIWebView的大小设置为276像素宽。

然后我加载了一些html,UIWebView的宽度不再是276像素。

我按如下方式设置了UIWebView:

// Setup Career about WebView
r.origin.x    = 22;
r.origin.y    = kWebViewYPos;
r.size.width  = 276;
r.size.height = 1;

UIWebView *tmpAboutWebView = [[UIWebView alloc] initWithFrame:r];
[self setSeminarAboutWebView:tmpAboutWebView];
[tmpAboutWebView release];

[[self seminarAboutWebView] setAutoresizesSubviews:YES];
[[self seminarAboutWebView] setUserInteractionEnabled:YES];
[[self seminarAboutWebView] setTag:999];
[[self seminarAboutWebView] setDelegate:self];

self.seminarAboutWebView.layer.borderColor = [UIColor redColor].CGColor; //Debugging
self.seminarAboutWebView.layer.borderWidth = 1.0; //Debugging


// Load the description for the selected seminar
NSString *htmlString = [[NSString alloc] initWithString:[[self seminar] about]];
DLog(@"%@", htmlString);
NSString *myDescriptionHTML = [NSString stringWithFormat:@"<html> \n"
                               "<head> \n"
                               "<link rel=\"stylesheet\" type=\"text/css\" href=\"career.css\" /> \n"
                               "</head> \n"
                               "<body>%@</body> \n"
                               "</html>", htmlString];

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];

[self.seminarAboutWebView loadHTMLString:myDescriptionHTML baseURL:baseURL]; 

[htmlString release];

可能导致此行为的原因是什么? HTML可以包含一些使UIWebView成为香蕉的标签吗?

我正在使用iOS 4.3 SDK构建。

Link to html code

编辑:我实际上发现了这个错误,我相信这是我自己的代码中没有UIWebView的错误。我根据UIWebView中加载的HTML数量动态设置UIWebView的高度。为此我使用了这段代码:

// Change the height dynamically of the UIWebView to match the html content
CGRect webViewFrame = webView.frame;
webViewFrame.size.height = 1;
webView.frame = webViewFrame;
CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
webViewFrame.size = fittingSize;
// Making sure that the webView doesn't get wider than 276 px I needed to add the below line and now it works
webViewFrame.size.width = 276; 
webView.frame = webViewFrame;

0 个答案:

没有答案