2014-05-20 142 views
0

嗨,我正在开发小型iPhone应用程序。我得到这样的服务器字符串在IOS7中显示html标记值iphone

You can download the MyApp on the Google Play store:<a href='https://play.google.com/store/apps/details?id=com.myapp' style='display:inline-block;padding:0px;margin-left:10px'>MyApp</a>", 

我想显示它为普通字符串与MyApp文本作为链接。这个怎么做。有没有办法做到这一点。 需要帮助。谢谢。

我试过,但仍然没有工作

NSAttributedString* attrStr = [[NSAttributedString alloc] 
           initWithString:@“You can download the MyApp on the Google Play store:<a href='https://play.google.com/store/apps/details?id=com.myapp' style='display:inline-block;padding:0px;margin-left:10px'>MyApp</a>" 

           attributes:[cell.answer.attributedText attributesAtIndex:0 effectiveRange:NULL]]; 
cell.answer.attributedText = attrStr; 
+0

'NSAttributedString'? 'UIWebView'? – Larme

+0

我使用普通的NSString,并没有在webview中显示。这是正常的标签。 – nilkash

+0

'NSAttributedString'等等。 – Larme

回答

0

你不能做到这一点与“只是一个普通标签”。

尝试使用NSAttributedString或将HTML代码放入UIWebView然后显示它。

我建议你采取看看OHAttributedLabel

编辑

与NSAttributedString

NSMutableAttributedString * appLabelString = [[NSMutableAttributedString alloc] initWithString:@"You can download the MyApp on the ...."]; 
[appLabelString addAttribute: NSLinkAttributeName value: @"http://www.itunes.com" range: NSMakeRange(21, 26)]; 
appLabel.attributedText = appLabelString; 
+0

嗨凯埃谢谢你的快速回放。我不想为此使用webview。有没有其他解决方案。 – nilkash

+0

如果你不想要webview(我不喜欢使用所有的时间),我建议你看看OHAttributedLabel。阅读它可以做什么在这里:https://github.com/AliSoftware/OHAttributedLabel#about-these-classes – Kaiusee

+0

是的,我检查它,但它已被弃用,因为IOS6我想用它的IOS7以及:( – nilkash