Xcode button to launch url

I created a simple application with a button in the bottom toolbar, and I cannot get the button to work. I tried to apply an action to it that would open the url when clicked, but that didn't work. So I deleted this action, and I hope someone can help. I sent a compressed xcode project to this URL https://www.box.com/s/5d45ce1df7d9dd0fe205

Any help is appreciated.

+5
source share
2 answers

Something like this will work. This is an example of a text button:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(0, 0, 100, 40)];
[button setBackgroundColor:[UIColor clearColor]];
[button setTitle:@"Google" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(openGoogleURL) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];

And button selector:

-(void)openGoogleURL
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com"]];
}
+25
source

viewcontroller webView. URL-.

  • .
  • webview . ( webView)
  • - ( , UIView )
  • in viewDidLoad :

     [super viewDidLoad];
     NSString *fullURL = @"http://google.pl";
    
     NSURL *url = [NSURL URLWithString:fullURL];
    
     NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    
    [self.webView loadRequest:requestObj];
    
-1

All Articles