在ios中集成CKEditor实现富文本编辑

在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]]];
        
}



使用了 ckeditor/samples/api.html(目录需要打全)文件, 然后将它显示在UIWebView中, 其中的javascript会自动链接到ckeditor包中的js文件, 就会显示出一个可编辑的富文本



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值