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

Posted 风痕

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)

[网页模板]

 

以上是关于iOS 使用GRMustache对HTML页面进行渲染的主要内容,如果未能解决你的问题,请参考以下文章

微信分享—ios和安卓机制居然不一样!

iOS开发Safari调试WebView页面

如何对一个HTML页面设置密码输入?

如何将一个.html导入进另一个.html页面?

如何对一个HTML页面设置密码输入?

ios内嵌app加载慢