开发者

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? c开发者_如何学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.


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.


Try an UITextView with editable=false and dataDetectorTypes = UIDataDetectorTypeLink


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜