我的UIWebView
总是小于设备的屏幕。无论我尝试什么,它都只是不会扩大网站规模以适应它的范围。
这是我的代码:
self.webView = [[UIWebView alloc] initWithFrame:
CGRectMake(.08 * width, .18 * height, .84 * width, .74 * height)];
self.webView.delegate = self;
self.webView.scrollView.delegate = self;
self.webView.scrollView.scrollEnabled = NO;
self.webView.scalesPageToFit = YES;
NSString *urlAddress = @"https://number26.de/app-tutorial/dist/new-feature-invite.html";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
[self.view.window addSubview:self.webView];
结果如下:
这就是它应该是什么样子(Google Chrome / Dev模式):
答案 0 :(得分:1)
okey,这是我的代码
- (void)viewDidLoad {
[super viewDidLoad];
self.webView = [[UIWebView alloc] init];
self.webView.frame = CGRectMake(.08 * self.view.frame.size.width, .18 * self.view.frame.size.height, .84 * self.view.frame.size.width, .74 * self.view.frame.size.height);
self.webView.delegate = self;
self.webView.scrollView.delegate = self;
self.webView.scrollView.scrollEnabled = NO;
NSString *urlAddress = @"https://s.number26.de/app-tutorial/dist/new-feature-invite.html";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
[self.view addSubview:self.webView];
self.webView.scalesPageToFit = YES;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
[self scaleToFit];
}
-(void)scaleToFit
{
if ([self.webView respondsToSelector:@selector(scrollView)])
{
UIScrollView *scroll=[self.webView scrollView];
float zoom=self.webView .bounds.size.width/scroll.contentSize.width;
[scroll setZoomScale:zoom animated:YES];
}
}
并在webView中查看完整网站。 ]
答案 1 :(得分:0)
添加此代码
-(void)webViewDidFinishLoad:(UIWebView *)webView {
[self scaleToFit];
}
-(void)scaleToFit
{
if ([self.webView respondsToSelector:@selector(scrollView)])
{
UIScrollView *scroll=[self.webView scrollView];
float zoom=self.webView .bounds.size.width/scroll.contentSize.width;
[scroll setZoomScale:zoom animated:YES];
}
}