Hi I am developing small iPhone application. I am getting string from server like this
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>",
I want to display it as normal string with MyApp text as link. How to do this. Is there any way to do this. Need Help. Thank you.
I tried this but still not working
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;
You can't do that with "just a normal label".
try to use NSAttributedString
or put HTML code in a UIWebView
then display it.
I would suggest you to take look at OHAttributedLabel
EDIT
with 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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.