IOS实现一个简单的浏览器

在工程中的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.
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值