UIWebView uiwebview 加载本地html

//.h文件
#import <Foundation/Foundation.h>

@interface NSString (Html)

+ (NSString *)importStyleWithHtmlString:(NSString *)HTML;
@end

//.m文件
#import "NSString+Html.h"

@implementation NSString (Html)

//样式和js要自己去写个合适的了
+ (NSString *)importStyleWithHtmlString:(NSString *)HTML
{
   
    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"style" ofType:@"css"];
    NSLog(@"-%@",filePath);
    NSString *replace = [NSString stringWithFormat:@"<link href="%@" rel="stylesheet" type="text/css"/>",filePath];
    HTML = [HTML stringByReplacingOccurrencesOfString:@"</head>" withString:replace];
    NSLog(@"HTML:%@",HTML);
    return HTML;

}
@end
//使用时候的代码
//先通过model里面的存html的字符串进行处理....转码,然后加载webView里
            NSURL *url = [NSURL URLWithString:model.shareInfo.url];
            
            NSData *data = [NSData dataWithContentsOfURL:url];
            NSString *newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            NSString *newHtml = [NSString importStyleWithHtmlString:newStr];
            [_webView loadHTMLString:newHtml baseURL:[NSURL fileURLWithPath:[NSBundle mainBundle].bundlePath]];

小结
此方法错做有个问题就是可以左右滑动,我用这个方法去抓一个html页面,最后导航 左右滑动 各种不和谐
介绍 或者尝试 可以参考方法:http://www.cnblogs.com/fengtengfei/p/4489247.html scrollView类目我没尝试
webView的介绍 可以参考此贴 http://www.oschina.net/question/213217_40635
WWDC2014中苹果有推出了WKWebView 新特性和使用可参考 http://blog.csdn.net/opengl_es/article/details/44855357

On the road。。。
原文地址:https://www.cnblogs.com/ianhao/p/4551774.html