WebView,嘿嘿,懒人专用,直接复制粘贴就能用,frame可调
来源:互联网 发布:smg淘宝店 编辑:程序博客网 时间:2024/05/18 00:14
在控制器的.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 = [[FirstViewalloc] initWithFrame:[UIScreenmainScreen].bounds];
self.view =self.fv;
}
- (void)viewWillAppear:(BOOL)animated {
self.tabBarController.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.890green:0.471blue:0.118alpha:1.000];
self.tabBarController.navigationController.title =@"空中夺宝";
}
- (void)viewDidLoad {
[superviewDidLoad];
web = [[UIWebViewalloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height -40)];
[websetUserInteractionEnabled:YES];//是否支持交互
web.delegate=self;
[websetOpaque:NO]; //opaque是不透明的意思
[websetScalesPageToFit:YES];//自动缩放以适应屏幕
[self.viewaddSubview:web];
NSURL *url = [NSURLURLWithString:@"http://www.baidu.com"];
[webloadRequest:[NSURLRequestrequestWithURL: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 = [[UIViewalloc]initWithFrame:[UIScreenmainScreen].bounds];
activityIndicatorView = [[UIActivityIndicatorViewalloc]initWithFrame:[UIScreenmainScreen].bounds];
[activityIndicatorViewsetCenter:opaqueView.center];
[activityIndicatorViewsetActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
[opaqueViewsetBackgroundColor:[UIColorblackColor]];
[opaqueView setAlpha:0.6];
[self.viewaddSubview:opaqueView];
[opaqueView addSubview:activityIndicatorView];
// Do any additional setup after loading the view.
}
-(void)webViewDidStartLoad:(UIWebView *)webView{
[activityIndicatorViewstartAnimating];
opaqueView.hidden =NO;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
[activityIndicatorViewstartAnimating];
opaqueView.hidden =YES;
}
//UIWebView如何判断 HTTP 404等错误
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSURL *url = [NSURLURLWithString:@"http://www.baidu.com"];
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if ((([httpResponse statusCode]/100) == 2)) {
// self.earthquakeData = [NSMutableData data];
[UIApplicationsharedApplication].networkActivityIndicatorVisible =YES;
[ webloadRequest:[ NSURLRequestrequestWithURL: url]];
web.delegate =self;
} else {
NSDictionary *userInfo = [NSDictionarydictionaryWithObject:
NSLocalizedString(@"HTTP Error",
@"Error message displayed when receving a connection error.")
forKey:NSLocalizedDescriptionKey];
NSError *error = [NSErrorerrorWithDomain:@"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 {
[superdidReceiveMemoryWarning];
// 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
运行吧,是不是成功了!~~
- WebView,嘿嘿,懒人专用,直接复制粘贴就能用,frame可调
- 时钟HTML,直接粘贴就能用
- bootstrap 修改 删除,直接复制粘贴就可以用
- webview复制粘贴文本
- PLSQL 复制粘贴/专用复制出现乱码
- 为何UE复制粘贴不能用了?
- easysize.h 文件,直接复制粘贴新建一个easysize.h文件就行了
- 特殊符号大全分享给大家,直接复制粘贴就可以使用了!
- Jquery 超级简单验证码 源代码 直接复制粘贴就猴了
- WordPress专用直接粘贴图片到文章编辑器插件Imagepaste
- WebView长按弹出复制粘贴
- 【java用I/O流下载】给个url就能下载,可复制粘贴直接使用
- win7远程桌面直接进行复制粘贴
- NotRxJava懒人专用指南
- RxJava懒人专用指南
- 用WEBBROWSER怎么复制粘贴不能用了
- UltraEdit复制粘贴功能为何不能用了?
- Cygwin复制,粘贴 直接用鼠标在黑框上选区即可,选区结束就已经复制了。cygwin里面Ctrl+V是不能粘贴的,用Shfit+ Insert(键盘上下左右方向键的上面) Cygwin 下切换目
- RGB to Gray 流行算法
- java基础学习总结——static关键字
- 虚拟机已死,容器才是未来?——VM + Container
- Objective-C Runtime 运行时之六:拾遗
- java.lang.ClassCastException: android.widget.*Layout$LayoutParams
- WebView,嘿嘿,懒人专用,直接复制粘贴就能用,frame可调
- openssl生成RSA公私钥对
- MYSQL必知必会读书笔记 第十和十一章 使用函数处理数据
- clion 使用技巧
- tomcat与web程序结构
- No cache or cacheManager properties have been set. Authorization cache cannot be obtained.
- Linux下Nagios的安装与配置
- Android消息传递机制----Handler
- rem使用