Search code examples
iphoneobjective-ccocoa-touchios4

How do i hyperlink in my iPhone Application?


I want a hyperlink in my iPhone Application, for example like in HTML:

<a href="www.yahoo.com"> Click here </a>

How can i do this in Objective-C?

The most important thing is that I don't want to show the actual link, I just want to show some text like "click here" and then it loads a link.

I'm currently using the below code. But as i told you I don't want to show the link instead I want something like "click here".

textView.text = @"http://stackoverflow.com";

textView.dataDetectorTypes = UIDataDetectorTypeLink;

Solution

  • Try this way:

    UIButton *btnFaceBook = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [btnFaceBook setFrame:CGRectMake(20, 290, 280, 30)];
    [btnFaceBook setBackgroundColor:[UIColor clearColor]];
    [btnFaceBook.titleLabel setFont:[UIFont boldSystemFontOfSize:16]];
    [btnFaceBook addTarget:self action:@selector(followFacebook) forControlEvents:UIControlEventTouchUpInside];
    [btnFaceBook setTitle:@"Click Here" forState:UIControlStateNormal];
    [contentView addSubview:btnFaceBook];
    

    below is the function to open the link:

    -(void) followFacebook{
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://facebook.com/"]];
    }