h文件
#import <Foundation/Foundation.h>
@interface MyIndexViewController : UIViewController<UIWebViewDelegate>
{
}
@end
m文件
//
// MyIndexViewController.m
// homepwner
//
// Created by waiman on 13-9-7.
// Copyright (c) 2013年 waiman. All rights reserved.
//
#import "MyIndexViewController.h"
@implementation MyIndexViewController
-(void)viewDidLoad
{
CGRect screenFrame = [[UIScreen mainScreen] applicationFrame];
UIView *webwrap = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenFrame.size.width, screenFrame.size.height)];
[webwrap setBackgroundColor:[UIColor redColor]];
UILabel *pageTitle = [[UILabel alloc] init];
[pageTitle setFrame:CGRectMake(0, 0, screenFrame.size.width, 30)];
[pageTitle setText:@"标题"];
[webwrap addSubview:pageTitle];
UIWebView *myweb = [[UIWebView alloc] initWithFrame:CGRectMake(0, 30, screenFrame.size.width, screenFrame.size.height-45-30-30)];
NSURL *url=[NSURL URLWithString:@"http://www.baidu.com"];
NSURLRequest *request=[[NSURLRequest alloc] initWithURL:url];
[myweb loadRequest:request];
[webwrap addSubview:myweb];
UIScrollView *pageScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, (int)screenFrame.size.height-94, screenFrame.size.width,50)];
pageScroll.scrollEnabled = YES; //拖动开启
pageScroll.contentSize = CGSizeMake(screenFrame.size.width, 50.0);//定义scrollView
[pageScroll setBackgroundColor:[UIColor greenColor]];
UIButton *pageBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[pageBtn setFrame:CGRectMake(0, 2, 100, 24)];
[pageBtn setTitle:@"页码" forState:UIControlStateNormal];
[pageBtn sizeToFit];
[self.view addSubview:webwrap];
[self.view addSubview:pageScroll];
[pageScroll addSubview:pageBtn];
}
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSLog(@"%@",[request URL]);
}
return YES;
}
@end