在ios上可以使用CKEditor和UIWebView实现富文本创建和编辑的功能.
首先下载CKEditor的包, 下载地址是http://download.cksource.com/CKEditor/CKEditor/CKEditor%204.2.2/ckeditor_4.2.2_standard.zip
然后将CKEditor解压后引入到工程中, 可以选中文件夹拖到XCode中, 注意上面要选中 Copy items into destination group's folder, 下面选择第二个, Create folder references for any added folders, 由于CKeditor中是js引用, 需要有目录结构, 因此拖到工程中时要保留文件夹目录
然后显示的时候需要使用一个UIWebView加载CKEditor中samples的一个html
- (void)viewDidLoad
{
[super viewDidLoad];
self.fileName = @"ckeditor/samples/api.html";
webView.delegate = self;
NSString *mainPath =[[[NSBundle mainBundle] bundlePath] stringByAppendingString:[@"/" stringByAppendingString:self.fileName]];
NSLog(mainPath);
NSString *basePath =[[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/ckeditor/samples/api.html"];
NSLog(self.fileName);
BOOL fileExistsBase = [[NSFileManager defaultManager]fileExistsAtPath:basePath];
BOOL fileExistsMain = [[NSFileManager defaultManager]fileExistsAtPath:mainPath];
NSString *basecontent = [NSString stringWithContentsOfFile:basePath
encoding:NSUTF8StringEncoding
error:NULL];
NSString *javaScriptCodeToReplaceContent = @"";
[[@"<script>CKEDITOR.instances.editor1.setData( '" stringByAppendingString:[[RevealController readLocalFile] stringByReplacingOccurrencesOfString:@"\n" withString:@""]] stringByAppendingString:@"');</script>"];
NSString *mainContent = [basecontent stringByAppendingString:javaScriptCodeToReplaceContent];
NSData *mainContentNSData = [mainContent dataUsingEncoding:NSUTF8StringEncoding];
NSLog(mainContent);
BOOL a = [mainContentNSData writeToFile:mainPath atomically:YES];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:basePath]]];
}