gpt4 book ai didi

html - iOS UIWebView 不缩放内容

转载 作者:太空宇宙 更新时间:2023-11-04 11:41:07 24 4
gpt4 key购买 nike

我有一个总是小于设备屏幕的 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];

结果是这样的: enter image description here

它应该是这样的(谷歌浏览器/开发模式): enter image description here

最佳答案

好的,这是我的代码

- (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 中查看完整的网站。 ]

关于html - iOS UIWebView 不缩放内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31326708/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com