【发布时间】:2020-02-06 18:12:17
【问题描述】:
我正在尝试在字符串中添加超链接。我有一个本地化的字符串,我把 %@ 用来格式化我的字符串。当我将属性字符串添加到我的字符串中时,属性格式给出的原始结果是NSLink = "https://www.example.com"。我找不到与字符串格式化程序相同的属性字符串格式化程序。在我的情况下如何实现相同的行为?
代码:
NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:@"Example"];
[str addAttribute: NSLinkAttributeName value: @"https:/www.example.com" range: NSMakeRange(0, str.length)];
NSMutableAttributedString *originalStr = [[NSMutableAttributedString alloc] initWithString: self.pageDescriptions[3].localized];
pageContentViewController.messageText = [NSString stringWithFormat:self.pageDescriptions[index].localized, str];
【问题讨论】:
标签: ios objective-c nsattributedstring nsmutableattributedstring stringwithformat