WKWebView加載HTML文本
NSString * htmlsTr = @"哦吧你不會(huì)比誰(shuí)都不休的白色修身<p>才能完呢沖破恩微博撇那狗騙你我餓夠了呢比你耳邊n偽軍抹去你問(wèn)邪惡</p><p><img src=\"http://yk3.gokuai.com/index/thumb?mount_id=1255485&type=jpeg&hash=c36c982f5d047666d7173c3625550152a2d403e6&filehash=ca9ab472b4914bc0b3e7eefc9fa0fa66d75091bf&big=1\" alt=\"Gravatar\" style=\"max-width:100%;display: block; position: relative; margin: auto;\"></p><p>熱敷已成為8哦鱷魚(yú)從背后有我餓</p><img src=\"http://yk3.gokuai.com/index/thumb?mount_id=1255485&type=jpeg&hash=565b67349cf2f08d4c373b350355adae46d7199c&filehash=169585a54ecc8311159717a1f8334ba0045a7532&big=1\" alt=\"Gravatar\" style=\"max-width:100%;display: block; position: relative; margin: auto;\"><p><a href=\"http://yk3.gokuai.com/file/hb14k046sx0l6gn2h471nkxm8i9zcau1#\" target=\"_blank\"><img src=\"http://dn-preview.gokuai.com/23/237b4494a9cc56b3c29dc1d34be8340774cf9ce6_1280.jpg\" alt=\"File\" style=\"max-width:100%;\"></a>去年細(xì)紋卡馬喬全部下次去把握和刺猬比歐巴</p>";
NSString *str = [NSString stringWithFormat:@"<head><style>img{max-width:%f !important;height:auto}</style></head>%@",kScreenWidth-30,htmlsTr];
UITextView * textview = [[UITextView alloc] initWithFrame:CGRectMake(0, 40, kScreenWidth, 100)];
[self addSubview:textview];
[textview mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.bottomView.mas_top).mas_offset(20);//10為按鈕高度的一半
make.left.mas_equalTo(self.bottomView.mas_left).mas_offset(10);
make.right.mas_equalTo(self.bottomView.mas_right).mas_offset(-10);
make.bottom.mas_equalTo(self.bottomView.mas_bottom).mas_offset(-10);
}];
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
textview.backgroundColor = [UIColor yellowColor];
textview.attributedText = attributedString;
效果圖
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者