- #import "ViewController.h"
- #import
- @interface ViewController ()
- @property (strong,nonatomic)UIwebView *webView;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- _webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
- [self.view addSubview:_webView];
- //通得模板渲染得到内容(可以随时修改对应标签的内容)NSString *rendering = [self demoFormatWithName:@"标题"value:@"内容"];
- NSLog(@"\n%@",rendering);
- NSString *path = [[NSBundle mainBundle] bundlePath];
- NSURL *baseUrl = [NSURL fileURLWithPath:path];
- [self.webView loadhtmlString:rendering baseURL:baseUrl];
- }
- //给template.html中对应的标签格式化内容-(NSString *)demoFormatWithName:(NSString *)name value:(NSString *)value{
- NSString *fileName =@"template.html";
- NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:fileName];
- NSString *template = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
- NSDictionary *renderObject = @{@"name":name,@"content":value};
- NSString *content = [GRMustacheTemplate renderObject:renderObject fromString:template error:nil];
- return content;
- }
- @end
来源: