UILabel显示html文本
2016-04-28 11:29
465 查看
有时候后台会返回给我们一串html的字符串,如果想要在label上显示,就需要做以下处理:
NSString * htmlString =
@"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
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];
NSString * htmlString =
@"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
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];
相关文章推荐
- MenuItem创建注意事项
- iOS9中UIDatePicker的用法
- <OJ_Sicily>Hanoi_Tower_Sequence
- 数据库中创建unique唯一约束
- String,StringBuffer与StringBuilder的区别
- Android蓝牙4.0API-类-BluetoothGattCharacteristic
- POJ 2299 Ultra-QuickSort(逆序数)
- iOS 之UIButton 使用详解
- Android蓝牙4.0API-类-BluetoothGattCallback
- iOS 之 UITableView 使用详解/性能优化/UITableViewCell/UITableViewController
- SSh结合Easyui实现Datagrid的分页显示
- make 2>&1 tee build_log.txt
- iOS 之 UITableView 使用详解
- Android蓝牙4.0API-类-BluetoothGatt
- UIControl 的基本使用方法和 Target-Action 机制
- 2016.04.28,英语,《Vocabulary Builder》Unit 20
- An instance 0x15718ca00 of class UITableView was deallocated while key value observers were still re
- iOS开发出现CUICatalog: Invalid asset name supplied:
- [CareerCup] 17.12 Sum to Specific Value 和为特定数
- iOS 之 UISegmentedControl 使用详解