How to add a hyperlink to the iPhone application?

In my iPhone app, I need to show a hyperlink to a website

How to add a hyperlink to a site in iPhone?

Actually, I want to transfer the link from my application to facebook using the facebook API.

So, how do I format the text so that it works like a hyperlink on facebook?

I still stick to this problem.

+7
objective-c iphone cocoa-touch ios4 hyperlink
source share
4 answers

It depends on where you want to put this link. If it is in a UITextView, you just need to enable it.

textView.text = @"Some text with link in it : http://http://stackoverflow.com"; textView.dataDetectorTypes = UIDataDetectorTypeLink; 

Learn more about the iOS help library .

Or, if you want to open Safari programmatically:

 NSURL *url = [ [ NSURL alloc ] initWithString: @"http://stackoverflow.com" ]; [[UIApplication sharedApplication] openURL:url]; [url release]; 

If you want to share on Facebook, you need to tell Safari to open a URL that displays a Facebook page that allows the user to share. Here is an example:

 NSString *urlString = @"http://stackoverflow.com"; //The url you want to share NSString *title = "The Title of the Page"; //The title you want to be displayed on Facebook NSString *shareUrlString = [NSString stringWithFormat:@"http://www.facebook.com/sharer.php?u=%@&t=%@", urlString , title]; //Create the URL string which will tell Facebook you want to share that specific page NSURL *url = [ [ NSURL alloc ] initWithString:shareUrlString ]; //Create the URL object [[UIApplication sharedApplication] openURL:url]; //Launch Safari with the URL you created [url release]; //Release the object if you don't need it 
+12
source share

Parth

Can you indicate where you need to insert hyperlink , this is my way to insert link in the iPhone app:

  NSMutableString *err=[[NSMutableString alloc] init]; [err appendString:@"<html><body style=\"background-color:black\" ><font size=3 face=\"helvetica\" color=\"white\" align=\"center\"><H3>Login Error</H3><p> "]; [err appendString:@"Please try again. If you forgot your password, you can retrieve it at<a href=\"ENTER YOUR LINK URL\"><font color=\"red\"> ENTER LINK TEXT</font></a>.</font></p></body></html>"]; } 
+1
source share

Drag a text element into your view controller and select its attribute inspector:

  • Set your text as “My site: www.mywebsitelink.com” and make sure that this type of text should be simple.
  • Mark your behavior as Selectable, Not Editable.
  • Mark as detection as links.

Run the project. You can see the link in the View Controller. Click the link that will take you to the safari and open a new tab.

+1
source share

My favorite shared library will be ShareKit. It is very easy to set up in your application, and will allow people to share via Facebook and other services. It is also customizable, so you can exchange it, change colors, and manage the services you want to share with.

Check out, http://www.getsharekit.com/

After adding it to the application, you can easily integrate it by creating a button

 [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share)]; //add the button to a navigation bar or tool bar. 

and then create the share method in your controller.

 - (void)share { // Create the item to share (in this example, a url) NSURL *url = [NSURL URLWithString:@"http://getsharekit.com"]; SHKItem *item = [SHKItem URL:url title:@"ShareKit is Awesome!"]; // Get the ShareKit action sheet SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item]; // Display the action sheet [actionSheet showFromToolbar:navigationController.toolbar]; } 
0
source share

All Articles