在Objective-C中将文本作为超链接 [英] Text as Hyperlink in Objective-C

查看:67
本文介绍了在Objective-C中将文本作为超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本标签,其文本设置为联系我们".当用户点击此标签时,应该启动safari来打开网页.我的疑问是如何将联系我们"设置为超链接.现在我无法修改我的代码包含UIWebView..请帮助我..我处于项目的最后阶段..如果可能,请帮助我提供示例代码..感谢您的所有时间

I have a text label with the text set as Contact Us.. When user taps on this label it should launch safari to open the web page.My doubt is how to make Contact Us as hyperlink.Now I can't modify my code to include a UIWebView..Please help me guys..I am in final stages of my project..If possible please help me with sample code..thanks for all your time

推荐答案

最简单的方法是使UILabel成为UIButton,对其进行样式设置(使用自定义"类型摆脱按钮外观).然后连接到打开野生动物园的动作.

The easiest way is to make the UILabel into a UIButton, style it (use Custom type to get rid of button look). Then connect to an Action that opens safari.

该操作应执行以下操作:

The action should do this:

NSURL *url = [[[ NSURL alloc ] initWithString: @"http://www.example.com" ] autorelease];
[[UIApplication sharedApplication] openURL:url];

这篇关于在Objective-C中将文本作为超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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