如何在UILabel中解析和显示超链接(电话号码/电子邮件地址等)? [英] How to parse and show hyperlinks (phone number/email addresses etc) in UILabel?

查看:82
本文介绍了如何在UILabel中解析和显示超链接(电话号码/电子邮件地址等)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone中几乎无处不在,您可以键入文本,操作系统会识别部分文本为超链接(例如电话号码,电子邮件地址)。但是我在我自己的应用程序中使用UILabel测试了它并且它不起作用。我该如何激活它?

Almost everywhere in the iPhone, you can type text and the OS will recognize portion of the text to be hyperlinks (phone numbers, email addresses for example). However I tested this in my own app with a UILabel and it doesn't work. How do I activate this?

iphone sdk是否提供开箱即用的功能,还是我自己必须完成解析逻辑(这是很多工作)?

Does the iphone sdk provide this functionality out of the box or do I have to do the parsing logic myself (which is a lot of work)?

推荐答案

您可以按如下方式使用UITextView:

You could use UITextView as follows:

UITextView *myView = [[UITextView alloc] initWithFrame: frame];
myView.text = @"this is http://google.com link";
myView.editable = NO;
myView.dataDetectorTypes = UIDataDetectorTypeLink;
//cell is the TableView's cell    
[cell.contentView addSubview:myView];
[myView release];

这篇关于如何在UILabel中解析和显示超链接(电话号码/电子邮件地址等)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆