Text as Hyperlink in Objective-C

2019-05-26 07:55发布

I have a text label with the text set as Contact Us.. When user taps on this label it should launch safari to open the web page.My doubt is how to make Contact Us as hyperlink.Now I can't modify my code to include a UIWebView..Please help me guys..I am in final stages of my project..If possible please help me with sample code..thanks for all your time

2条回答
疯言疯语
2楼-- · 2019-05-26 08:11

for XOS use NSWorkspace instead:

- (IBAction)btnPressed:(id)sender {
   NSURL *url = [[NSURL alloc] initWithString: @"https://www.google.com"];
   [[NSWorkspace sharedWorkspace] openURL:url];
}
查看更多
Deceive 欺骗
3楼-- · 2019-05-26 08:37

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

The action should do this:

NSURL *url = [[[ NSURL alloc ] initWithString: @"http://www.example.com" ] autorelease];
[[UIApplication sharedApplication] openURL:url];
查看更多
登录 后发表回答