I've created a simple app that has a button in the bottom toolbar and I can't seem to get the button to work. I've tried to attach an action to it that will open a URL when pressed but it did not work. So I've removed that action and I'm hoping someone can help. I've posted the compressed xcode project at this URL https://www.box.com/s/5d45ce1df7d9dd0fe205
Any help is appreciated.
SwiftUI gives us a dedicated Link view that looks like a button but opens a URL in Safari when pressed. It's easy enough to use – just give it a title for the button, plus a destination URL to show, like this: Link("Learn SwiftUI", destination: URL(string: "https://www.hackingwithswift.com/quick-start/swiftui")!)
Something like this would work. This is an example of a text-only 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 the button's selector:
-(void)openGoogleURL
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com"]];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With