UIWebView [web视图]

#import "ViewController.h"
#define width_screen self.view.bounds.size.width
#define height_screen self.view.bounds.size.height
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    //创建一个文本框
    [self creatTextField];
    
    //创建button
    [self creatButton];
    
    [self createWebView];
}

#pragma mark    ------------------------textField
- (void)creatTextField
{
    
    UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(20, 20, 150, 50)];
    
    [self.view addSubview:tf];
    
    tf.borderStyle = UITextBorderStyleRoundedRect;
    
    tf.placeholder = @"http://www.baidu.com";
    
    tf.textColor = [UIColor orangeColor];
    tf.keyboardType = UIKeyboardTypeASCIICapable;
    
    tf.tag = 21;

}

#pragma mark    ------------------------button
- (void)creatButton
{
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(200, 20, 60, 50)];
    
    [self.view addSubview:btn];
    
    btn.backgroundColor = [UIColor grayColor];
    
    [btn setTitle:@"Go" forState:UIControlStateNormal];
    
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    
    //注册事件
    [btn addTarget:self action:@selector(onclick) forControlEvents:UIControlEventTouchUpInside];

}

-(void)onclick
{
    UIWebView *webW = (id)[self.view viewWithTag:20];
    
    UITextField *tf = (id)[self.view viewWithTag:21];
    
    NSURL *url = [NSURL URLWithString:tf.text];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    [webW loadRequest:request];
    
    //放弃第一响应者
    [tf resignFirstResponder];
}//(0, 110, w_screen, h_screen-110)

#pragma mark    ------------------------web view
- (void)createWebView
{
    UIWebView *wv = [[UIWebView alloc]initWithFrame:CGRectMake(0, 70, width_screen, height_screen-110+40)];

    
    [self.view addSubview:wv];
    
    wv.tag = 20;
}


@end

转载于:https://www.cnblogs.com/wanghengheng/p/4827415.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值