Programming/Non programming

Sunday, March 28, 2010

iPhone:Adding URL to the text?

iPhone:

How to add URL link to the text:

There are two ways to do that.

1. Via under button controls:

i) Create a button in view. Make the button as 'custom' so that you will not see button borders at runtime and will look like just a text.
ii) Create a button action like below:

-(IBAction) LaunchURL : (id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http:/www.corpusmobilelabs.com/"]];
}

Click on the button, you should be success!

2. Via under TouchEvent on a control:

i) Create a UILabel and write text like your URL www.yourwebsite.com
ii) Make sure UILabel linked with UILabel declaration in code and UserInteraction checkbox is
enabled in I.B.
iii) Add the below touch event code in your code, which will execute the launching URL only when the created UILabel is touched.

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint point = [[touches anyObject] locationInView:urlLabel];
if( [urlLabel hitTest:point withEvent:nil] )
[ [UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www. yourwebsite.com"] ];
else
[super touchesEnded:touches withEvent:event];
}

That's it, you got to go!!!

Thank you for followers!

Cheers,

M.P.Prabakar
Senior Systems Analyst.

Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..

No comments:

Post a Comment