怎么展示html格式的商品詳情-創(chuàng)新互聯(lián)

這篇文章主要介紹了怎么展示html格式的商品詳情的相關(guān)知識,內(nèi)容詳細(xì)易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇怎么展示html格式的商品詳情文章都會有所收獲,下面我們一起來看看吧。

清江浦網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,清江浦網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為清江浦千余家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務(wù)好的清江浦做網(wǎng)站的公司定做!

1、創(chuàng)建WKWebview

- (WKWebView *)webView{
if (!_webView) {
_webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, _window_width, _backScrollView.height)];
_webView.navigationDelegate = self;
_webView.opaque = NO;
_webView.multipleTouchEnabled = YES;
_webView.scrollView.delegate = self;
_webView.scrollView.bounces = NO;
_webView.scrollView.showsVerticalScrollIndicator = NO;
_webView.scrollView.scrollEnabled = NO;
_webView.scrollView.panGestureRecognizer.enabled = NO;
}
return _webView;
}

2、獲取服務(wù)端返回的html的字符串

NSString *description = minstr([storeInfo valueForKey:@“description"]);
//我這里更改一下html的格式,讓其符合手機(jī)端展示,如果服務(wù)端返回的就是手機(jī)端展示的樣式,這就可以不用更改 直接用就可以了
NSString * htmlStyle = @" <style type=\"text/css\"> *{min-width: 0% !important;max-width: 100% !important;} table{ width: 100% !important;} img{ height: auto !important;}  </style> ";
description = [htmlStyle stringByAppendingString:description];
NSString *aaa = @"<meta content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0\" name=\"viewport\">";
description = [aaa stringByAppendingString:description];
[_webView loadHTMLString:description baseURL:nil];

3、在WKWebView加載完成的代理方法中更改webView的frame

- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
[webView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
//更改webview的frame
_webView.frame = CGRectMake(0, _goodListView.bottom, _window_width, [result doubleValue]);//將WKWebView的高度設(shè)置為內(nèi)容高度
//更改背景scrollview的滑動范圍
 _backScrollView.contentSize = CGSizeMake(0, _webView.bottom);
}];
    
//    插入js代碼,對圖片進(jìn)行點(diǎn)擊操作
[webView evaluateJavaScript:@"function assignImageClickAction(){var imgs=document.getElementsByTagName('img');var length=imgs.length;for(var i=0; i < length;i++){img=imgs[i];if(\"ad\" ==img.getAttribute(\"flag\")){var parent = this.parentNode;if(parent.nodeName.toLowerCase() != \"a\")return;}img.onclick=function(){window.location.href='image-preview:'+this.src}}}" completionHandler:^(id object, NSError *error) {
        
}];
[webView evaluateJavaScript:@"assignImageClickAction();" completionHandler:^(id object, NSError *error) {
        
}];
imageArray = [self getImgs:description];
 
 
}
#pragma mark -- 獲取文章中的圖片個數(shù)
- (NSMutableArray *)getImgs:(NSString *)string
{
   
NSMutableArray *arrImgURL = [[NSMutableArray alloc] init];
NSArray *array = [string componentsSeparatedByString:@"<img"];
NSInteger count = [array count] - 1;
 
 
for (int i = 0; i < count; i++) {
NSString *jsString = [NSString stringWithFormat:@"document.getElementsByTagName('img')[%d].src", i];
[_webView evaluateJavaScript:jsString completionHandler:^(NSString *str, NSError *error) {
            
if (error ==nil) {
[arrImgURL addObject:str];
}
       
}];
}
imageArray = [NSMutableArray arrayWithArray:arrImgURL];
    
    
return arrImgURL;
}

4、在WKWebView的代理方法中攔截圖片添加的點(diǎn)擊方法,可使用HZPhotoBrowser來展示圖片

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
    
 NSURLRequest *request = navigationAction.request;
if ([request.URL.scheme isEqualToString: @"image-preview"])
 {
        
NSString *url = [request.URL.absoluteString substringFromIndex:14];
        
        
 //啟動圖片瀏覽器, 跳轉(zhuǎn)到圖片瀏覽頁面
if (imageArray.count != 0) {
            
HZPhotoBrowser *browserVc = [[HZPhotoBrowser alloc] init];
browserVc.imageArray = imageArray;
browserVc.imageCount = imageArray.count; // 圖片總數(shù)
browserVc.currentImageIndex = (int)[imageArray indexOfObject:url];//當(dāng)前點(diǎn)擊的圖片
[browserVc show];
            
}
decisionHandler(WKNavigationActionPolicyAllow);
return;
        
}
 
decisionHandler(WKNavigationActionPolicyAllow);
NSLog(@"在發(fā)送請求之前:%@",navigationAction.request.URL.absoluteString);

關(guān)于“怎么展示html格式的商品詳情”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對“怎么展示html格式的商品詳情”知識都有一定的了解,大家如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道。

網(wǎng)站標(biāo)題:怎么展示html格式的商品詳情-創(chuàng)新互聯(lián)
鏈接地址:http://bm7419.com/article44/dsecee.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)用戶體驗(yàn)、網(wǎng)站排名移動網(wǎng)站建設(shè)、云服務(wù)器、外貿(mào)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)