首页 > 移动平台 > 详细

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

时间:2016-04-06 15:09:49      阅读:753      评论:0      收藏:0      [点我收藏+]

第三方控件[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页面进行渲染

原文:http://www.cnblogs.com/qzp2014/p/5359214.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!