OGeek|极客世界-中国程序员成长平台

标题: ios - iPad UIWebView 与 iPhone 网站 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:43
标题: ios - iPad UIWebView 与 iPhone 网站

我在 iPad 应用中有一个 UIWebView,应该显示移动 Google。它像 iPhone 一样宽 320 像素,我已经设置了用户代理,以便它加载移动 Google。但是该网站比 UIWebView 更宽,尽管该网站针对移动屏幕进行了优化。 这是我创建 Web View 的代码:

    NSDictionary *userAgentDictionary = [[NSDictionary alloc] initWithObjectsAndKeys"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3", @"UserAgent", nil];
    [[NSUserDefaults standardUserDefaults] registerDefaults:userAgentDictionary];

    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 320, 480)];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString"http://www.google.com"]];
    [webView loadRequest:request];
    [self addSubview:webView];

现在是这样的:

how it looks like now

我可以做些什么来使它适合?它也应该适用于其他非移动页面。



Best Answer-推荐答案


改变这一行:

webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 320, 480)];

到这里:

webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, self.view.frame.size.height)];

关于ios - iPad UIWebView 与 iPhone 网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8477439/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4