coder net
coder net

Reputation: 3475

Display a url link in iphone app view preferably in a label

I'm trying to display a link on my login view for new user registration. This link will say something like "Not a member? click here to register. This link when clicked should open up Safari. What are my options. It would have been nice to have a click event on UILabel. I can do it with a button but it looks weird and would like to avoid using a button, unless it can look like a Label. Don't want to try UIWebView, it does not seem to suit my needs.

Any other ideas? I searched online but could not find a useful approach.

Upvotes: 4

Views: 2769

Answers (3)

radsdau
radsdau

Reputation: 501

Even better: Place a RoundRectButton, set its type to Custom, adjust the text so it looks like a link, then tie an action to the button.

If the button text is the actual URL you want to visit, tie all link buttons to the same Action handler:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:sender.currentTitle]];

for 'http://' included, or

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"http://" stringByAppendingString:sender.currentTitle]]];

otherwise, i.e., 'clean' url such as "www.foo.net"

You get the added bonus of immediate visual feedback when the link button is pressed to.

Upvotes: 0

coder net
coder net

Reputation: 3475

if someone else is looking for something like this and not able to figure out anything else, do the following..

Display a label and put a button on top of it, make it invisible (type set to custom) and detect the click on it.. you can do anything, label, image of the text etc etc.

Upvotes: 4

fsaint
fsaint

Reputation: 8759

Try an UITextView with editable=false and dataDetectorTypes = UIDataDetectorTypeLink

Upvotes: 3

Related Questions