Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-31-2009, 10:27 AM   #1 (permalink)
New Member
 
Join Date: Jul 2009
Posts: 24
Smile open url when press label

Hello,

I need a url to open up in safari when the user press on a label.

What do I need to do?

Thanks. :]
dorkauf is offline   Reply With Quote
Old 07-31-2009, 10:57 AM   #2 (permalink)
Spaztastic
iPhone Dev SDK Supporter
 
Null & Void's Avatar
 
Join Date: Jul 2009
Age: 19
Posts: 10
Default

UILabels don't have any methods for triggering events when they are clicked, but you can detect a click manually like this...

//Triggered when the screen is touched
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//If touch location is inside the label then...
if (CGRectContainsPoint(label.frame, [[[event allTouches] anyObject] locationInView:mainView]))
{
//Open webpage
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
}
}

______________________________
n00bs are people too...
My first app Motion Sick
.
Null & Void is offline   Reply With Quote
Old 07-31-2009, 10:58 AM   #3 (permalink)
iPhone Developer
 
Join Date: Sep 2008
Location: Canada
Posts: 149
Default

NSURL *url = [NSURL URLWithString:@"your url"];
[[UIApplication sharedApplication] openURL:url];
Henning is offline   Reply With Quote
Old 07-31-2009, 11:12 AM   #4 (permalink)
New Member
 
Join Date: Jul 2009
Posts: 24
Default

Quote:
Originally Posted by Null & Void View Post
UILabels don't have any methods for triggering events when they are clicked, but you can detect a click manually like this...

//Triggered when the screen is touched
- (void)touchesBeganNSSet *)touches withEventUIEvent *)event
{
//If touch location is inside the label then...
if (CGRectContainsPoint(label.frame, [[[event allTouches] anyObject] locationInView:mainView]))
{
//Open webpage
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
}
}

______________________________
n00bs are people too...
My first app Motion Sick
.
what do i need to write instead of the mainView?
dorkauf is offline   Reply With Quote
Old 07-31-2009, 11:58 AM   #5 (permalink)
Spaztastic
iPhone Dev SDK Supporter
 
Null & Void's Avatar
 
Join Date: Jul 2009
Age: 19
Posts: 10
Default

"mainView" is a UIView object that represents your main view or whatever view your working in. To create it, go into interface builder and create a new outlet called "mainView" an connect it with your view, then save and write the class files.

______________________________
n00bs are people too...
My first app Motion Sick
.
Null & Void is offline   Reply With Quote
Reply

Bookmarks

Tags
label, safari, url

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 261
19 members and 242 guests
2WeeksToGo, @sandris, AdamL, ADY, BrianSlick, Dani77, diyora, F_Bryant, GHuebner, HDshot, headkaze, mer10, prchn4christ, Rudy, smithdale87, Thompson22, timle8n1, Touchmint, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,748
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:55 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0