iOS 使用GRMustache对HTML页面进行渲染

第三方控件[GRMustanche] 

OC 

Swift 

//测试版本 7.3.2

最终效果图:

 

 

【使用方法&& 核心代码】

通过cocoapods 导入

#import <GRMustache.h>

 

- (NSString *) testFormatWithName: (NSString *) name value: (NSString *) vaue {

    NSString * fileName = @"test.html";

    //获取完整的html 文件路径  带后缀名

    NSString * path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent: fileName];

     //编码

    NSString * template = [NSString stringWithContentsOfFile: path encoding: NSUTF8StringEncoding error: nil];

    NSDictionary * renderObject = @{@"name": name, @"content": vaue};

    NSString * content = [GRMustacheTemplate renderObject: renderObject fromString: template error: nil];

    return  content;

}

NSString * htmlstr = [self testFormatWithName: @"王晓明" value: @"你好"];

   [self.webView loadHTMLString: htmlstr baseURL: nil];

 

 

[DEMO 地址] (提取码:b3e0)

[网页模板]

 

posted @ 2016-04-06 14:25  云影风雨  阅读(468)  评论(0编辑  收藏  举报