解决商品详情页面加载标签语言的方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhangyulin311/article/details/79613300

服务器返回:<p><img src=\"http:\/\/www.hebeishilian.com\/ueditor\/php\/upload\/image\/20180103\/1514960629377900.jpg\" style=\"\" title=\"1514960629377900.jpg\"\/><\/p><p><img src=\"http:\/\/www.hebeishilian.com\/ueditor\/php\/upload\/image\/20180103\/1514960629404582.jpg\" style=\"\" title=\"1514960629404582.jpg\"\/><\/p><p><img src=\"http:\/\/www.hebeishilian.com\/ueditor\/php\/upload\/image\/20180103\/1514960629174968.jpg\" style=\"\" title=\"1514960629174968.jpg\"\/><\/p><p><img src=\"http:\/\/www.hebeishilian.com\/ueditor\/php\/upload\/image\/20180103\/1514960629636950.jpg\" style=\"\" title=\"1514960629636950.jpg\"\/><\/p><p><img src=\"http:\/\/www.hebeishilian.com\/ueditor\/php\/upload\/image\/20180103\/1514960630282186.jpg\" style=\"\" title=\"1514960630282186.jpg\"\/><\/p><p><img src=\"http:\/\/www.hebeishilian.com\/ueditor\/php\/upload\/image\/20180103\/1514960630717838.jpg\" style=\"\" title=\"1514960630717838.jpg\"\/><\/p><p><img src=\"http:\/\/www.hebeishilian.com\/ueditor\/php\/upload\/image\/20180103\/1514960630260520.jpg\" style=\"\" title=\"1514960630260520.jpg\"\/><\/p><p><img src=\"http:\/\/www.hebeishilian.com\/ueditor\/php\/upload\/image\/20180103\/1514960630865574.jpg\" style=\"\" title=\"1514960630865574.jpg\"\/><\/p><p><img src=\"http:\/\/www.hebeishilian.com\/ueditor\/php\/upload\/image\/20180103\/1514960630604992.jpg\" style=\"\" title=\"1514960630604992.jpg\"\/><\/p><p><img src=\"http:\/\/www.hebeishilian.com\/ueditor\/php\/upload\/image\/20180103\/1514960630317413.jpg\" style=\"\" title=\"1514960630317413.jpg\"\/><\/p><p><br\/><\/p>"


//首先添加js,把获取到的信息中的图片及字体设置成自己想要展示的模式

- (void)loadContent:(NSString *)str{

    NSString *htmlString = [NSString stringWithFormat:@"<html> \n"

                            "<p> \n"

                            "<style type='text/css'> \n"

                            "body {font-size:15px;}\n"

                            "</style> \n"

                            "</p> \n"

                            "<body>"

                            "<script type='text/javascript'>"

                            "window.onload = function(){\n"

                            "var $img = document.getElementsByTagName('img');\n"

                            "for(var p in $img){\n"

                            "$img[p].style.width = '100%%';\n"

                            "$img[p].style.height ='auto'\n"

                            "}\n"

                            "}"

                            "</script>%@"

                            "</body>"

                            "</html>",str];

    

    dispatch_async(dispatch_get_main_queue(), ^{

        [self.webView loadHTMLString:htmlString baseURL:nil];

    });


}

//在

webViewDidFinishLoad中用通知获取高度

- (void)webViewDidFinishLoad:(UIWebView *)webView{

    CGSize fittingSize = [webView sizeThatFits:CGSizeZero];

    self.height = fittingSize.height;

    if (fittingSize.width > SCREEN_SIZE.width) {

        CGSize fittingSize = [webView systemLayoutSizeFittingSize:CGSizeZero];

        self.height = fittingSize.height;

        [[NSNotificationCenter defaultCenter] postNotificationName:@"WEBVIEW_HEIGHT_LOAD" object:nil userInfo:nil];


    }else{

        webView.frame = CGRectMake(0, 0, fittingSize.width, fittingSize.height);

        [[NSNotificationCenter defaultCenter] postNotificationName:@"WEBVIEW_HEIGHT" object:@{@"height":[NSString stringWithFormat:@"%f",_height]} userInfo:nil];

    }

    

    

}

在详情的VC中获取这个高度,并赋值给全局变量,刷新

- (void)noti:(NSNotification *)sender{

    _heightDetail = [sender.object[@"height"] floatValue];

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

        NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:3];

        [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationTop];

        [self netWorkLoadding:NO];

    });

}




阅读更多
换一批

没有更多推荐了,返回首页