我正在开发uiwebview,它应该加载来自服务器的动态网址。 我希望在我的iPhone应用程序中显示它适合iPhone屏幕大小,并且它应该放大和缩小。
我正在使用的代码是:
m_pView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 430)];
m_pView.backgroundColor = [UIColor blackColor];
self.view = m_pView;
UIWebView *aWebView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 1, 320, 400)] autorelease];
aWebView.dataDetectorTypes = UIDataDetectorTypeNone;
aWebView.delegate = self;
NSString* url = [NSString stringWithFormat: @"http://%@",[m_URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
aWebView.scalesPageToFit = YES;
aWebView.autoresizesSubviews = YES;
aWebView.frame = self.view.bounds;
NSURL *aURL = [NSURL URLWithString: url];
NSURLRequest *aRequest = [NSURLRequest requestWithURL:aURL];
//load the index.html file into the web view.
[aWebView loadRequest:aRequest];
[m_pView addSubview:aWebView];
self.m_webView = aWebView;
请告诉我如何在不丢失放大/缩小功能的情况下实现适合iphone屏幕尺寸的webview。
提前致谢。
答案 0 :(得分:0)
使用以下代码
yourWEbView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
yourWEbView.contentMode = UIViewContentModeScaleAspectFit;
答案 1 :(得分:0)
问题可能在这一行: aWebView.frame = self.view.bounds;
为什么在将webview添加到m_pView时设置self.view的界限?