html 标签字符串如下
protocolConfig.title = @"个人隐私保护指引";
protocolConfig.content = @"欢迎您使用新闻!在使用前,请充分阅读并理解<a href='https://....cn/privacy_cy_policy.jsp?v=1.2' style='color:#00A5EB'>《隐私政策》</a>和<a href='https://....cn/agreement.html' style='color:#00A5EB'>《用户使用协议》</a>,点击同意按钮代表您已知悉并同意前述协议及以下约定:<br>1.我们可能会申请位置权限,用于为您推荐本地新闻、发表信息时展示位置信息等; <br>2.我们可能会申请存储空间权限,用于您保存图片、上传图片或视频等; <br>3.我们可能会申请相机权限,用于您发表信息时拍摄图片或视频等; <br>4.我们可能会申请麦克风权限,用于您拍摄视频时录制声音; <br>5.我们可能会申请系统设备权限收集设备信息,用于为您推送新闻、确保服务的稳定性等; <br>6.我们可能会申请拨打电话权限,用于您报料时拨打报料电话。 <br>上述权限均不会默认或强制开启,我们会在相关的应用场景中向您申请。";
关键代码如下
<a href='https://m.thepaper.cn/privacy_cy_policy.jsp?v=1.2' style='color:#00A5EB'>《隐私政策》</a>
生成html富文本
}
NSString *preString = [NSString stringWithFormat:@"<span style=\"color:#%@\">",[defaultColor hexStringFromColor]];
NSString *suffixString = @"</span>";
NSString *newString = [[preString stringByAppendingString:string] stringByAppendingString:suffixString];
NSDictionary *dic = @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSMutableAttributedString * attrStr = [[NSMutableAttributedString alloc] initWithData:[newString dataUsingEncoding:NSUnicodeStringEncoding] options:dic documentAttributes:nil error:nil];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.maximumLineHeight = lineHeight;
paragraphStyle.minimumLineHeight = lineHeight;
paragraphStyle.alignment = NSTextAlignmentLeft;
paragraphStyle.paragraphSpacing = 1;
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
paragraphStyle,NSParagraphStyleAttributeName,
@0.0f,NSBaselineOffsetAttributeName,
font,NSFontAttributeName,
nil];
[attrStr addAttributes:attributes range:NSMakeRange(0, attrStr.length)];
效果如图
点击蓝色部分文案就跳转到相应的网页了