最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
iOS UITextView加载有HTML标签的HTML代码示例
时间:2022-06-25 23:35:47 编辑:袖梨 来源:一聚教程网
在开发中,我们加载HTML最常用的是UIWebView,其实UITextView也可以加载HTML代码。
- (void)viewDidLoad {
[super viewDidLoad];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 40, kScreenWidth, kScreenHeight - 50)];
[self.view addSubview:textView];
//HTML代码
NSString *htmlStr = @"
hiuehuirhfiefguihuiefuwifhewufcehsifhoifhiofhwohfwiohfwoicehicehiheifjkhuhuihwefhuiwhfibfiwehfurwhfuiwhfuiwefhuirwhfiw
hviurhrihvuerhviohvoiwehvewiohiowhviowvhoiheiohihuihguguygigdusichvregtgtgegtgvrtvtrbtrbtrbtrbtrbtbtvrgeggergrbrt
hiuehuirhfiefguihuiefuwifhewufcehsicehicehiheifjkhuhuihwefhuiwhfibfiwehfurwhfuiwhfuiwefhuirwhfiw
";
//对图片大小进行处理,适应屏幕宽度
NSString *newString = [htmlStr stringByReplacingOccurrencesOfString:@"
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[newString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
textView.attributedText = attributedString;
}
注意:在info.plist中配置:
注:
// 当前屏幕宽度
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
// 当前屏幕高度
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
相关文章
- 张雪峰死亡原因揭秘:急速运动心源猝死 03-25
- 张雪峰今年多大呀?怎么会突然猝死了? 03-25
- 张雪峰死了真的假的?张雪峰死亡原因揭秘 03-25
- 张雪峰是谁?张雪峰死了热搜霸榜?张雪峰个人资料及简介 03-25
- 41岁张雪峰因病去世:面对危险疾病该如何预防和紧急救治 03-25
- 古龙群侠录核心阵容如何搭配?知名角色推荐 03-24