现在的位置: 首页 > 综合 > 正文

CKEditor使用方法

2013年08月13日 ⁄ 综合 ⁄ 共 1984字 ⁄ 字号 评论关闭

具体CKEditor怎么加入到项目中并引用,我就不多说了,很简单。

 

http://ckeditor.com/ 官网,或者google都能找到

 

下面是引入后的目录结构,供参考,其中iOS5Editor.html是自己创建的,随便起名字。

iOS5Editor.html的代码如下:

 

 <head> 

    <title>Replace Textareas by Class Name — CKEditor Sample</title> 

    <meta content="text/html; charset=utf-8" http-equiv="content-type" /> 

    <script type="text/javascript" src="ckeditor.js"></script> 

    <script type="text/javascript" src="config.js"></script> 

    <script type="text/javascript"> 

        function getData() 

        { 

            alert(CKEDITOR.instances.editor1.getData()); ; 

        } 

    </script> 

</head> 

<body> 

  

        <p> 

            <label for="editor1"> 

                Editor 1:</label> 

    <textarea class="ckeditor" cols="80" id="editor1" name="editor1" rows="10" style="margin-top:199px;"><p>This is some <strong>sample text</strong>. You are using <a href="http://ckeditor.com/">CKEditor</a>.</p></textarea> 

        </p> 

        <script type="text/javascript"> 

        //<![CDATA[ 

            CKEDITOR.replace( 'editor1', 

            { 

                toolbar : 'MyToolbar' 

            }); 

  

        //]]> 

        </script> 

        <p> 

        <!--input type="button" value="Button" onMouseDown="getData()"> 

              

        </p--> 

  

</body> 

 

 

 ViewController中代码片段如下。

 

读取iOS5Editor.html,然后放到UIWebView中,这时候就能看到效果了。

 

 NSString *path = [[NSBundle mainBundle] pathForResource:@"iOS5Editor" ofType:@"html"]; 

NSString *htmlString = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; 

NSURL *url = [NSURL fileURLWithPath:path]; 

  

_webView = [[UIWebView alloc] initWithFrame:CGRectMake(20, 50, self.view.frame.size.width-40, self.view.frame.size.height-200)]; 

_webView.backgroundColor = [UIColor grayColor]; 

[_webView loadHTMLString:htmlString baseURL:url]; 

_webView.delegate = self; 

  

[self.view addSubview:_webView];  

 

如果想获取html中的内容,写个button事件,看下面代码:

 

 - (void)sendMail:(id)sender 

    NSString *msg = [_webView stringByEvaluatingJavaScriptFromString:@"CKEDITOR.instances.editor1.getData()"]; 

  

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:msg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

    [alert show]; 

    [alert release]; 

 

 

 

 
 
 

抱歉!评论已关闭.