ios web view 解析Html格式的文本

#import "ViewController.h"

@interface ViewController ()<UIWebViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIWebView *web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    web.delegate = self;
    web.backgroundColor = [UIColor whiteColor];
    [web loadHTMLString:@"html格式文本" baseURL:nil];
//    [web loadHTMLString:self.htmlString baseURL:nil];
    [self.view addSubview:web];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    //    方法中加入js代码
    NSString *str = @"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '30%'";
    [webView stringByEvaluatingJavaScriptFromString:str];
}

推荐阅读更多精彩内容