天天看點

iOS webwiew加載本地html,樣式不正确?解決方法

加載方法:

//Load

-(void)loadHTMLFile {
    
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path isDirectory:YES];
    NSString * htmlPath = [[NSBundle mainBundle] pathForResource:@"indexhelp" ofType:@"html"];
    NSString * htmlCont = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
    [self.webview loadHTMLString:htmlCont baseURL:baseURL];
    
}
           

簡單說 CSS沒載入

你把編譯完成產出的Html.app檔打開, 然後看檔案結構, 你會發現CSS, html, 圖片�*****n案都是在根目錄

是以我隻舉其中一個例子 , 剩下的自己解決

把index.html內

<link href="Css/Xtgj.css" target="_blank" rel="external nofollow"  rel="stylesheet" type="text/css" />
           

改成

<link href="Xtgj.css" target="_blank" rel="external nofollow"  rel="stylesheet" type="text/css" />
           

這樣就可以載入一部分的CSS

君凱商聯網-iOS-字唐名僧

繼續閱讀