Text as a hyperlink in Objective-C

I have a text label with the text set to "Contact us". When the user clicks on this label, he has to launch the safari to open the web page. My doubt is how to contact us as a hyperlink. Now I cannot change my code to include the UIWebView. Please help me guys. I am in the final stages of my project. If possible please help me with some sample code .. thanks for all your time.

+2


source to share


2 answers


The easiest way is to make a UILabel in a UIButton, style it (use Custom type to get rid of the button view). Then connect to the Action that opens the safari.

The action should do this:



NSURL *url = [[[ NSURL alloc ] initWithString: @"http://www.example.com" ] autorelease];
[[UIApplication sharedApplication] openURL:url];

      

+5


source


for XOS, NSWorkspace is used instead:



- (IBAction)btnPressed:(id)sender {
   NSURL *url = [[NSURL alloc] initWithString: @"https://www.google.com"];
   [[NSWorkspace sharedWorkspace] openURL:url];
}

      

0


source







All Articles