UITextFile 輸入中文問題

2021-10-07 01:15:57 字數 1047 閱讀 9377

-(bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string{

nsstring *lang = [[uitextinputmode currentinputmode]primarylanguage];//鍵盤輸入模式

if ([lang isequaltostring:@"zh-hans"]) {// 簡體中文輸入,包括簡體拼音,健體五筆,簡體手寫

uitextrange *selectedrange = [textfield markedtextrange];

//獲取高亮部分

uitextposition *position = [textfield positionfromposition:selectedrange.start offset:0];

nsstring * newtext = [textfield textinrange:selectedrange];

//沒有高亮選擇的字,則對已輸入的文字進行字數統計和限制

if (!position) {

if (textfield.text.length>10) {

textfield.text=[textfield.text substringwithrange:nsmakerange(0, 10)];

//有高亮選擇的字串,則暫不對文字進行統計和限制

else{

// 中文輸入法以外的直接對其統計限制即可,不考慮其他語種情況

else{

[self filtercharactor:textfield.text withregex:@"[^\u4e00-\u9fa5·|•]"];

//        if (textfield.text.length>8) {

//            textfield.text=[textfield.text substringwithrange:nsmakerange(0, 8)];

return yes;

Sublime Text 輸入中文顯示方框問號亂碼

用了sublime text 2好久,今天遇到這個問題,網上很難找到相關的解決方案,因此被困擾了很久,故此記錄下來以備再次發生。問題描述 在重灌系統前一切正常,重灌系統後沒有再次安裝sublime text 2直接執行安裝路徑下的sublime text.exe,當輸入中文符號時就出現了如下圖所示的...

docker容器中bash無法輸入中文問題

docker容器中bash無法輸入中文問題 首先通過互動模式下進入映象,通過終端 輸入locale檢視顯示資訊是否如下 lang language lc ctype posix lc numeric posix lc time posix lc collate posix lc monetary p...

python輸入中文 python輸入中文

python版本3.6 解決方法很簡單,在定義filehandler時指定encoding就好了import loggingfile hanlder logging.filehandler filename example.log,encoding utf 8 因為看python的logging.f...