iOS | App跳转Safari直接打开指定的网页

2018-09-20  本文已影响128人  Rickie_Lambert

代码如下:

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UIButton *btnSkip = [UIButton buttonWithType:UIButtonTypeCustom];
    btnSkip.frame = CGRectMake((self.view.frame.size.width - 280)/2, 30, 280, 50);
    btnSkip.backgroundColor = [UIColor redColor];
    [btnSkip setTitle:@"测试跳转到Safari" forState:UIControlStateNormal];
    [btnSkip setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btnSkip addTarget:self action:@selector(skipToSafari) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnSkip];
    
    
}

- (void)skipToSafari
{
    // app跳转打开safari 跳转打开指定设置的网页
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http:www.baidu.com"]];
}
上一篇 下一篇

猜你喜欢

热点阅读