ZSSRichTextEditor使用過程中遇到的問題

最近公司要做一個(gè)論壇類的app,有一個(gè)類似簡書發(fā)布文章的富文本編輯器功能,于是各種百度谷歌,最終決定使用ZSSRichTextEditor這個(gè)庫,當(dāng)然使用過程中遇到了很多問題.

1.當(dāng)內(nèi)容輸入多的時(shí)候,內(nèi)容超過鍵盤,就會(huì)不顯示.

分析了一下原因,因?yàn)閏ontentHeight高度過高,導(dǎo)致被鍵盤覆蓋內(nèi)容無法顯示,那么我看下ZSSRichTextEditor的demo,在鍵盤升起的監(jiān)聽方法中可以看到

[self setFooterHeight:(keyboardHeight -8)];

[self setContentHeight: self.editorViewFrame.size.height];

作者之所以要給footer設(shè)置一個(gè)高度就是為了撐起一個(gè)鍵盤高度,我們只需要將contentHeight值減小即可,比如我們減100的高度

[self setContentHeight: self.editorViewFrame.size.height - 100];

這是我們發(fā)現(xiàn)就可以正常顯示了.

2.當(dāng)插入圖片時(shí),圖片過大不超出屏幕

我們只需要在插入圖片的js方法中在標(biāo)簽中插入內(nèi)嵌式的css樣式即可

zss_editor.insertImage =function(url, alt) {

? ? zss_editor.restorerange();

? ?var html = '<img src="' + url + '" alt="' + alt + '" style="width:100% !important;"/>';

? ? zss_editor.insertHTML(html);

? ? zss_editor.enabledEditingItems();

}

3.增加標(biāo)題輸入框

在editor.html中加入輸入框

? ? ? ? <input style="border:none;border-bottom: 1px dashed red;width:100%;height:44px;font-size:20px;" id="article_title" maxlength="35" type="text" placeholder="請(qǐng)輸入標(biāo)題">


獲取標(biāo)題值

-(NSString*)getTitle{

? ? NSString *htmlNum = @"document.getElementById('article_title').value";

? ? NSString *numHtmlInfo = [self.editorView stringByEvaluatingJavaScriptFromString:htmlNum];

? ? returnnumHtmlInfo;

}

4.分割線間距太小

zss_editor.setHorizontalRule方法替換為一下方法

zss_editor.setHorizontalRule =function() {

? ? //? ? document.execCommand('insertHorizontalRule', false, null);

? ? varhr_html ="<br />"+'<hr />'+"<br />";

? ? document.execCommand('insertHTML',false, hr_html);

? ? zss_editor.enabledEditingItems();

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容