gpt4 book ai didi

ios - 在 iOS UIWebView 中为 iPhone 和 iPad 加载不同的 HTML

转载 作者:行者123 更新时间:2023-11-29 03:21:31 26 4
gpt4 key购买 nike

我可以让 iPhone 和 iPad 加载相同的 HTML 文件,但是我想根据程序加载的设备加载更优化的页面。

ViewController.h:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIWebView *webView;

@end

ViewController.m:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
NSString *html = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];

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

[_webView loadHTMLString:html baseURL:baseURL];

// disable scrolling
_webView.scrollView.scrollEnabled = NO;
_webView.scrollView.bounces = NO;
}



- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

我尝试创建一个新的 socket ,但我似乎遇到了重叠的代码。

如何使用通用版本加载适用于 iPad 和 iPhone 的不同 HTML 文件?

最佳答案

只需使用一个 WebView 。您只需要两个不同的 HTML 文件。

然后你的代码可以是这样的:

NSURL *url;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
url = [[NSBundle mainBundle] URLForResource:@"index-iphone" withExtension:@"html"];
} else {
url = [[NSBundle mainBundle] URLForResource:@"index-ipad" withExtension:@"html"];
}

这假设您的应用程序包中同时存在 index-iphone.htmlindex-ipad.html 文件。

关于ios - 在 iOS UIWebView 中为 iPhone 和 iPad 加载不同的 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21032233/

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