objective-c - UILabel 文本为 html 文本

标签 objective-c ipad ios4

我遇到了一个小问题。

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

就像我正在使用一个 Objective 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;

关于objective-c - UILabel 文本为 html 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5743844/

相关文章:

iphone - UITextView 委托(delegate)类在单击 TextView 时崩溃?!这是怎么回事?

ios - swift 2 : Strange Objective C -> Swift method's signature conversion

iphone - 多个异步 Web 服务请求 NSURLConnection iOS

objective-c - NSDictionary setValue :forKey: -- getting "this class is not key value coding-compliant for the key"

iphone - 禁用快速查看

iphone - 图片IO : <ERROR> JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?

iphone - 为什么自动生成的 IBOutlet @properties 不使用 @synthesize button = _button 约定?

iphone - “Application tried to present modally an active controller” iOS5 错误

ios - 将 iPhone 应用程序转换为通用、XCode 5.1 和 Storyboard。漏洞?

iphone - 持久化NSMUtablearray是核心数据实体的属性