-1

I want to give hyperlink on my iPhone/iPad view.I want to click on some text and open new view.I have tried to give hyperlink on my UILable .But it dint work...How should I do this?

Khushbu Shah
  • 282
  • 4
  • 12
  • I have extended or subclassed UILabel and I have made a custom control for the label. If you need that label then please let me know – Parth Bhatt Feb 15 '12 at 05:51
  • @Khushbu Shah : You can get this answer only by search on SO or google. Just try to search something by yourself. – Devang Feb 15 '12 at 06:14

6 Answers6

1

Set a UIButton with button type set to Custom and set its title to the website address, in its action you can give the code to open the url.

iNoob
  • 3,364
  • 2
  • 26
  • 33
1

Do this in your Touches Begin or end method....

    -(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event
        {
           UITouch* touch = [[touches allObjects] objectAtIndex:0];

           CGPoint location = [touch locationInView: [touch view]];

           CGRect firstLinkRect = CGRectMake(36, 11, 150, 12);  // your UILabel Rect

            // NSLog(@"X: @%f \n Y: @%f",location.x, location.y);

           if (CGRectContainsPoint(firstLinkRect, location)) 
             {
              //NSLog(@"Get First point");
                NSURL *target = [[NSURL alloc] initWithString:@"http://www.google.com"];
               [[UIApplication sharedApplication] openURL:target];
             }
         }
Anshul Jain
  • 903
  • 6
  • 9
0

you can use uibutton for that and put image which look like link.

It will solve your problem.

0

Is this text must be a part of textView or label? you may add UIButton with custon type and your linktext/image/or something

SentineL
  • 4,682
  • 5
  • 19
  • 38
0

This if you want to put the hyperlink into iphone development for the we use the UIButton in which the we gives the IBAction method to give him

And best example give here so u can get the idea about it.

Refrence link here.

Happy coding

Thanks ,

@samuel

Nimit Parekh
  • 16,776
  • 8
  • 50
  • 72
0

The best solution is to use a UIButton, and have it link out as (others have said). You can set the button's type to be UIButtonTypeCustom.

If you want your text to be underlined like a real hyperlink, I find the best solution is this one.

Community
  • 1
  • 1
Robotnik
  • 3,643
  • 3
  • 31
  • 49