OC代码生成html文件

- (void)MyHTMLCreate {
   
    //先弄个地址 文件名叫test.html
    NSString *filepath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"test.html"];
   
    //字符串,所有要写入html的内容都塞到这个字符串里,后面创建文件时一并塞进去
    NSMutableString *htmlString = [[NSMutableString alloc] init];
   
    [htmlString appendString:@"\n"];
   
    [htmlString appendString:@"\n"];
   
    [htmlString appendString:@"\n"];
   
    //[htmlString appendString:@""];//控制行间距
   
    [htmlString appendString:@"\n"];
   
    [htmlString appendString:@"\n"];
   
    [htmlString appendString:@"\n"];
   
    [htmlString appendString:@"

\n"];
   
    [htmlString appendString:@"
\n"];
   
    //这里可追加内容
    //[htmlString appendString:content];
   
    [htmlString appendFormat:@"
\n"];
   
    [htmlString appendString:@"
OC代码生成HTML
\n"];
   
    [htmlString appendFormat:@"速度要快,姿势要帅!!!
\n"];
   
    [htmlString appendFormat:@"15960758000
\n"];
   
    [htmlString appendString:@""];
   
    [htmlString appendString:@"自古深情留不住,总是套路得人心"];
   
    [htmlString appendString:@"
\n"];
   
    [htmlString appendString:@"
\n"];
   
    [htmlString appendString:@"
\n\n\n"];
   
    //塞那么多字符串就是为了这一句,写入文件
   
    [htmlString  writeToFile:filepath atomically:YES encoding:NSUTF8StringEncoding error:nil];
   
    //  htmlstring=[NSString stringWithContentsOfFile:filepath encoding:NSUTF8StringEncoding error:nil];
   
}


生成之后用浏览器打开如图,APP用UIwebview加载也可以正常显示。

OC代码生成html文件_第1张图片

你可能感兴趣的:(OC代码生成html文件)