如何在iPhone应用程序中添加超链接? [英] How to add hyperlink in iPhone app?
问题描述
在我的iPhone应用程序中,我需要显示指向网站的超链接
如何在iPhone编程中为网站添加超链接? b
$ b
实际上,我想使用facebook API将我的应用程序的链接传递到Facebook。
那么我应该如何格式化我的文本
div>
这取决于你想放置这个链接。
如果它在一个UITextView,你只需要启用
textView.text = @ in it:http:// http://stackoverflow.com;
textView.dataDetectorTypes = UIDataDetectorTypeLink;
有关 iOS参考库
或者如果您要以程序方式打开Safari:
NSURL * url = [[NSURL alloc] initWithString:@http://stackoverflow.com];
[[UIApplication sharedApplication] openURL:url];
[url release];
EDIT 因此,如果您想在Facebook上分享, Safari打开一个URL,它将显示一个允许用户共享的Facebook页面。这里是一个例子:
NSString * urlString = @http://stackoverflow.com;
//你想分享的url
NSString * title =页面的标题;
//你想在Facebook上显示的标题
NSString * shareUrlString = [NSString stringWithFormat:@http://www.facebook.com/sharer.php?u=% @& t =%@,urlString,title];
//创建一个URL字符串,告诉Facebook你想要共享那个页面
NSURL * url = [[NSURL alloc] initWithString:shareUrlString];
//创建URL对象
[[UIApplication sharedApplication] openURL:url];
//使用您创建的URL启动Safari
[url release];
//如果不需要,释放对象
In my iPhone app, I require to show the hyperlink to a website
How can I add hyperlink for a website in iPhone programming?.
Actually i want to pass the link from my app onto facebook using facebook API.
So how should I format my text such that it works as hyperlink on facebook?
I am still stuck with this issue.
It depends where you want to put this link. If it is in a UITextView, you just have to enable
textView.text = @"Some text with link in it : http://http://stackoverflow.com";
textView.dataDetectorTypes = UIDataDetectorTypeLink;
More info on iOS reference library
Or if you want to open Safari programatically :
NSURL *url = [ [ NSURL alloc ] initWithString: @"http://stackoverflow.com" ];
[[UIApplication sharedApplication] openURL:url];
[url release];
EDIT So if you want to share on facebook, you need to tell Safari to open an URL which will display a Facebook page that allows the user to share. Here is an example :
NSString *urlString = @"http://stackoverflow.com";
//The url you want to share
NSString *title = "The Title of the Page";
//The title you want to be displayed on Facebook
NSString *shareUrlString = [NSString stringWithFormat:@"http://www.facebook.com/sharer.php?u=%@&t=%@", urlString , title];
//Create the URL string which will tell Facebook you want to share that specific page
NSURL *url = [ [ NSURL alloc ] initWithString:shareUrlString ];
//Create the URL object
[[UIApplication sharedApplication] openURL:url];
//Launch Safari with the URL you created
[url release];
//Release the object if you don't need it
这篇关于如何在iPhone应用程序中添加超链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!