WebView,嘿嘿,懶人專用,直接複製貼上就能用,frame可調
在控制器的.h檔案中
#import <UIKit/UIKit.h>
#import "FirstView.h"
@interface FirstViewController : UIViewController<UIWebViewDelegate> {
UIWebView *web;
UIActivityIndicatorView *activityIndicatorView;
UIView *opaqueView;
}
@property (nonatomic, strong) FirstView *fv;
@end
在.m中,如下:
#import "FirstViewController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
- (void)loadView {
[super loadView];
self.fv = [[FirstView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.view = self.fv;
}
- (void)viewWillAppear:(BOOL)animated {
self.tabBarController.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.890 green:0.471 blue:0.118 alpha:1.000];
self.tabBarController.navigationController.title = @"空中奪寶";
}
- (void)viewDidLoad {
[super viewDidLoad];
web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 40)];
[web setUserInteractionEnabled:YES];//是否支援互動
web.delegate=self;
[web setOpaque:NO]; //opaque是不透明的意思
[web setScalesPageToFit:YES];//自動縮放以適應螢幕
[self.view addSubview:web];
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
[web loadRequest:[NSURLRequest requestWithURL:url]];
//2.載入本地檔案資源
/* NSURL *url = [NSURL fileURLWithPath:filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];*/
//3.讀入一個HTML,直接寫入一個HTML程式碼
//NSString *htmlPath = [[[NSBundle mainBundle]bundlePath]stringByAppendingString:@"webapp/loadar.html"];
//NSString *htmlString = [NSString stringWithContentsOfURL:htmlPath encoding:NSUTF8StringEncoding error:NULL];
//[webView loadHTMLString:htmlString baseURL:[NSURL fileURLWithPath:htmlPath]];
opaqueView = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
activityIndicatorView = [[UIActivityIndicatorView alloc]initWithFrame:[UIScreen mainScreen].bounds];
[activityIndicatorView setCenter:opaqueView.center];
[activityIndicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
[opaqueView setBackgroundColor:[UIColor blackColor]];
[opaqueView setAlpha:0.6];
[self.view addSubview:opaqueView];
[opaqueView addSubview:activityIndicatorView];
// Do any additional setup after loading the view.
}
-(void)webViewDidStartLoad:(UIWebView *)webView{
[activityIndicatorView startAnimating];
opaqueView.hidden = NO;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
[activityIndicatorView startAnimating];
opaqueView.hidden = YES;
}
//UIWebView如何判斷 HTTP 404 等錯誤
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if ((([httpResponse statusCode]/100) == 2)) {
// self.earthquakeData = [NSMutableData data];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[ web loadRequest:[ NSURLRequest requestWithURL: url]];
web.delegate = self;
} else {
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:
NSLocalizedString(@"HTTP Error",
@"Error message displayed when receving a connection error.")
forKey:NSLocalizedDescriptionKey];
NSError *error = [NSError errorWithDomain:@"HTTP" code:[httpResponse statusCode] userInfo:userInfo];
if ([error code] == 404) {
// NSLog(@"xx");
web.hidden = YES;
}
}
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
執行吧,是不是成功了!~~
相關文章
- 蘋果Mac電腦的複製貼上不能用蘋果Mac
- 複製貼上不了怎麼辦?Mac複製貼上不瞭解決方法Mac
- Label--自定義可貼上複製的Label
- 破解“無法複製貼上”
- vue 中實現複製貼上Vue
- wordpress從word複製貼上公式公式
- vim總結貼上/複製篇
- clipboard.js無法複製貼上JS
- JavaScript實現複製和貼上功能JavaScript
- macOS如何複製貼上無格式文字Mac
- UILabel實現複製貼上功能UI
- Linux下複製貼上快捷鍵Linux
- 利用JS實現複製/貼上功能JS
- 電腦無法複製貼上怎麼回事?電腦無法複製貼上的解決方法
- Linux的VI (刪除貼上,複製)Linux
- ClipboardJS複製貼上外掛的使用JS
- 學習正則(告別複製貼上)
- Linux 裡的複製與貼上 (轉)Linux
- vim複製文字到系統貼上板
- win10 office word不能複製貼上怎麼辦_win10 office word不能複製貼上如何處理Win10
- cad複製快捷鍵命令 cad怎麼複製貼上圖形
- js複製文字到貼上板(Clipboard.writeText())JS
- oracle erp不能和其他文件複製貼上Oracle
- 複製貼上程式碼真的有問題嗎?
- UE複製貼上二進位制檔案
- 在vSphere中實現複製貼上功能
- Win10無法複製貼上如何修復_win10複製貼上用不了的解決步驟Win10
- 如何在不同的專案中共用前端資源,告別複製貼上前端
- python3網路爬蟲開發實戰-線上版-可複製貼上Python爬蟲
- win10系統無法複製貼上怎麼辦 win10電腦複製貼上功能失效如何修復Win10
- 使用 xclip 在 Linux 命令列中複製貼上Linux命令列
- 前端 JavaScript 複製貼上的奧義——Clipboard 物件概述前端JavaScript物件
- 如何禁止網頁複製貼上?我學fei了網頁
- Linux下命令列中的複製和貼上Linux命令列
- vim在系統剪下板的複製與貼上
- (轉)iOS長按textView複製貼上顯示中文iOSTextView
- Delphi_Excel例子:單元格複製貼上 (轉)Excel
- 做了20套資料視覺化模板,不用敲程式碼,直接複製就能用視覺化