适配wkwebview字符串显示,查看大图

2023-06-25  本文已影响0人  马铃薯蜀黍

NSString * foreString = @"<html><head><meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <style type="text/css"> body { line-height:150%} </style>
<style>img{max-width: 100%; width:auto; height:auto;}</style><style>iframe {display: block;max-width:100%;
margin-top:10px; margin-bottom:10px;}</style><style type="text/css">
</style></head><body style="margin:0;padding:0">";
NSString * tailString = @"</body></html>";
NSString * htmlString = [NSString stringWithFormat:@"%@%@%@",foreString,htmlString,tailString];
[self.webView loadHTMLString:htmlString baseURL:nil];
[self.webView addTapImageGesture];//查看大图

=======================================

import <WebKit/WebKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface WKWebView (images)

-(void) addTapImageGesture;

@end

NS_ASSUME_NONNULL_END

import "WKWebView+images.h"

@implementation WKWebView (images)

-(void) addTapImageGesture
{
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.delegate = (id)self;
[self addGestureRecognizer:tapGesture];
}
//这里增加手势的返回,不然会被WKWebView拦截

// UIImage *clickImg = [UIImage imageWithData:imgData];
// if (clickImg)
// {
//
//
// }
NSArray *imgArr = @[url];
// NSMutableArray *tempArray = [[NSMutableArray alloc] init];
// [tempArray addObject:clickImg];

        //TO对图片的操作
            NSMutableArray * bigImageArray = [NSMutableArray array];
            for (int i = 0; i < imgArr.count; i ++) {
                YBIBImageData *data = [YBIBImageData new];
                data.imageURL = [NSURL URLWithString:imgArr[i]];
                data.allowSaveToPhotoAlbum = YES;

// data.defaultLayout.zoomScaleSurplus = 3;
[bigImageArray addObject:data];
}

            //    [bigImageArray addObject:data];
            
            YBImageBrowser *browser = [YBImageBrowser new];
            
            browser.dataSourceArray = bigImageArray;
            browser.currentPage = 0;
            [browser show];
            
        }
    }
}];

}

@end

上一篇 下一篇

猜你喜欢

热点阅读