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?
-
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 Answers
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.

- 3,364
- 2
- 26
- 33
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];
}
}

- 903
- 6
- 9
you can use uibutton for that and put image which look like link.
It will solve your problem.
Is this text must be a part of textView or label? you may add UIButton with custon type and your linktext/image/or something

- 4,682
- 5
- 19
- 38
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.
Happy coding
Thanks ,
@samuel

- 16,776
- 8
- 50
- 72
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.
-
Thanks to all...uptill now I was using UIButton for sthis.. And it is working perfect.... But I just wanted to know that is there possible to have hyperlinks on UILable ? Is it possible or not. – Khushbu Shah Feb 15 '12 at 05:36
-
1@KhushbuShah: Yes it is possible by subclassing UILabel and I have made a custom control for the same. Please let me know if you need it. – Parth Bhatt Feb 15 '12 at 05:52
-
@ParthBhatt - Right now I don't have need for this..This time I have used UIButton for hyperlink.But just for a sake of knowledge I was asking.. – Khushbu Shah Feb 15 '12 at 05:57
-
-
@ParthBhatt - If you don't have problem than can You give me just for knowing? – Khushbu Shah Feb 15 '12 at 06:02
-
@KhushbuShah: Yes sure. But where should I send it? Whats your Email ID? – Parth Bhatt Feb 15 '12 at 06:12
-
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/7727/discussion-between-parth-bhatt-and-khushbu-shah) – Parth Bhatt Feb 15 '12 at 09:44
-
@KhushbuShah: Ok now you can delete your email ID for the privacy purpose. – Parth Bhatt Feb 15 '12 at 09:45
-
-
@ParthBhatt- you told me about PHP project..Can you give me information...? – Khushbu Shah Feb 20 '12 at 05:11