iOS7加载富文本(UILabel)

iOS  7加载富文本
NSString * htmlString = @" Some html string \n This is some text! ";  
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];  
UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds];  
myLabel.attributedText = attrStr;  
[self.view addSubview:myLabel];
注意:只能在iOS7以后运行,因为NSAttributedString 在iOS7以后才添加的  ,在iOS7以前 不能使用该属性。切记

你可能感兴趣的:(IOS博客专栏)