在工程中的ViewController的编码:
#import "ViewController.h"
@interface ViewController (){
//系统的进度条
UIActivityIndicatorView *activityView;
UISlider *slider;
UIWebView *webView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 1、创建uiwebview,加载网页
webView=[[UIWebView alloc] initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
webView.delegate=self;
[self.view addSubview:webView];
//把url放在浏览器上试一试
//创建网页地址
NSURL *url=[NSURL URLWithString:@"http://www.baidu.com"];
//创建执行请求
NSURLRequest *request=[[NSURLRequest alloc] initWithURL:url];
//执行请求
[webView loadRequest:request];
[self createProgressview];
[self creatUISlider];
}
//创建滑动进度条
- (void)creatUISlider{
slider=[[UISlider alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 50)];
[slider addTarget:self action:@selector(sliderChange) forControlEvents:UIControlEventValueChanged];
slider.maximumValue=200.0f;
slider.minimumValue=80.0f;
slider.value=80.0f;
[self.view addSubview:slider];
}
//创建加载进度条
-(void)createProgressview
{ //进度条的宽高
activityView=[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 30, 40, 40)];
activityView.backgroundColor=[UIColor grayColor];
[activityView setActivityIndicatorViewStyle: UIActivityIndicatorViewStyleWhite];
[activityView startAnimating];
activityView.center=self.view.center;
[self.view addSubview:activityView];
}
-(void)sliderChange{
NSLog(@"slider.value=%f",slider.value);
NSString *changeStr=[NSString stringWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust='%f%%'",slider.value];
//javascript的代码
[webView stringByEvaluatingJavaScriptFromString:changeStr];
}
//weiview加载完成
- (void)webViewDidFinishLoad:(UIWebView *)webView{
NSLog(@"加载完成");
[activityView stopAnimating];
}
//webview开始加载
- (void)webViewDidStartLoad:(UIWebView *)webView
{
NSLog(@"开始加载");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}