WKWebView 加载本地 CSS 样式

// 从 Bundle 中加载 css
- (void)loadFromBundle {
    NSMutableString *html = [NSMutableString string];
    [html appendString:@""];
    [html appendFormat:@""];
    [html appendString:@"

测试文案

"]; NSURL *myUrl = [NSURL fileURLWithPath:[NSBundle mainBundle].bundlePath]; [_webView loadHTMLString:html baseURL:myUrl]; } // 从本地文件中加载 css - (void)loadFromLocal { NSMutableString *html = [NSMutableString string]; [html appendString:@""]; [html appendFormat:@""]; [html appendString:@"

测试文案

"]; NSString *cssPath = [NSString stringWithFormat:@"%@",NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)]; NSURL *myUrl = [NSURL fileURLWithPath:cssPath]; [_webView loadHTMLString:html baseURL:myUrl]; }

你可能感兴趣的:(WKWebView 加载本地 CSS 样式)