tags:

views:

13

answers:

3

I am having the UIButton name as "Buy now".If any one touch the button,the external link should open in the safari browser.How can i achieve this?

A: 

Create a button, and give it a target to a selector that opens Safari with the link.

Basic example:

Make a UIButton

UIButton *button = [[UIButton alloc] initWithFrame:...];
[button addTarget:self action:@selector(someMethod) forControlEvents:UIControlEventTouchUpInside];

Then the method to open the URL

-(void)someMethod {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.ca"]];
}

Don't forget to give your button a proper frame and title, and to add it to your view.

dc
A: 

That's easy. You set the target and selector for the button, then inside the selector you call safari to open your link.

Code to call safari:

- (void)buttonPressed {
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.co.uk"]];

}
vodkhang
A: 
- (IBAction)buyNowButtonPressed {
    NSString *s = [ NSString stringWithFormat:@"http://www.sample.com/buynowpage"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:s]];
}
hotpaw2