如何在字符串上建立超链接并在Facebook中共享[iOS] [英] How to make hyperlink on a String and share in Facebook [iOS]

查看:277
本文介绍了如何在字符串上建立超链接并在Facebook中共享[iOS]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSString,我可以在 Facebook & Twitter .我的要求是,文本将成为在 Facebook 上共享后的链接.在 Facebook 上,当用户单击该文本,然后直接转到该链接.

I have a NSString which one I use for share on Facebook & Twitter. My requirement is that text will be a link after share on Facebook. On Facebook when user click on that text, then direct go to that link.

我的代码如下:

NSInteger Score = [[NSUserDefaults standardUserDefaults] integerForKey:@"K_ScoreVal"];

SLComposeViewController *Facebooksheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[Facebooksheet setInitialText:[NSString stringWithFormat:@"I just completed level 1.1 and score is %d points.",Score]];
[[CCDirector sharedDirector] presentViewController:Facebooksheet animated:YES completion:nil];

我刚完成1.1级,得分为455分.这是我的文字,我在 Facebook 上分享了该文字.但是当用户单击此文本时,则直接转到链接.同时,我想将此文本设置为超链接.

I just completed level 1.1 and score is 455 points. This is my text, which one I share on Facebook. But when user click on this text, then direct go to a link. Meanwhile I want to make this text as a hyperlink.

请建议我.

推荐答案

您是否尝试过使用属性字符串?

Have you tried using Attributed Strings?

NSString *shareString = [[NSAttributedString alloc] initWithString:@"I just completed level 1.1 and score is 455 points." attributes:@{NSLinkAttributeName: @"http://yourlink.com"}];

这篇关于如何在字符串上建立超链接并在Facebook中共享[iOS]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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