UITextView 加載html文本(圖片自適應(yīng))

WKWebView加載HTML文本

NSString * htmlsTr = @"哦吧你不會(huì)比誰(shuí)都不休的白色修身<p>才能完呢沖破恩微博撇那狗騙你我餓夠了呢比你耳邊n偽軍抹去你問(wèn)邪惡</p><p><img src=\"http://yk3.gokuai.com/index/thumb?mount_id=1255485&amp;type=jpeg&amp;hash=c36c982f5d047666d7173c3625550152a2d403e6&amp;filehash=ca9ab472b4914bc0b3e7eefc9fa0fa66d75091bf&amp;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&amp;type=jpeg&amp;hash=565b67349cf2f08d4c373b350355adae46d7199c&amp;filehash=169585a54ecc8311159717a1f8334ba0045a7532&amp;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;

效果圖

image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容