0
我可以同時加載iPhone和iPad加載相同的HTML文件,但是我想根據加載程序加載哪個設備來加載更優化的頁面。在iOS中加載不同的HTML UIWebView for iPhone和iPad
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
我試圖創建一個新的出路,但我似乎遇到了相互重疊的代碼。
如何爲通用版本的iPad和iPhone加載不同的HTML文件?
這太好了!我注意到的一件事是,第一行需要關閉,導致'NSURL * url;'謝謝,我會接受這個作爲最佳答案,一旦SO允許我。 – block14
糟糕 - 這是一個錯字。我已經添加了分號。謝謝。 – rmaddy