UILabel 文本作为 html 文本

2023-12-19

我被一个小问题困住了。

我需要使用一个句子,其中前两个单词为粗体,后两个单词为斜体。喜欢:

I am using an O目标C开发商。

怎么做。这在 Objective C 中可能吗?


对于 iOS7,你可以使用这个:

NSString * htmlString = @"<html><body> Some html string </body></html>";
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];

UILabel * myLabel = [UILabel alloc] init];
myLabel.attributedText = attrStr;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

UILabel 文本作为 html 文本 的相关文章

随机推荐