3
我想類似的泰米爾鍵盤如何添加自定義語言的UITextView文本
功能:當我按下A鍵,我想展示அ,當我按AA我想顯示ஆ。
這是我到目前爲止嘗試過的。
NSMutableString *updatedText = [[NSMutableString alloc] initWithString:textView.text];
[updatedText insertString:text atIndex:range.location];
NSLog(@"%i",range.location);
NSRange replaceRange = range , endRange = range;
if (text.length > 0)
{
NSLog(@" text length %i",text.length);
replaceRange.length= text.length;
}
else
{
replaceRange.length = 2; // length of "hi" is two characters
replaceRange.location -= 1; // look back one characters (length of "hi" minus one)
}
int replaceCount = [updatedText replaceOccurrencesOfString:@"a" withString:@" அ" options:NSCaseInsensitiveSearch range:replaceRange];
// replaceCount = [updatedText replaceOccurrencesOfString:@"aa" withString:@" ஆ" options:NSCaseInsensitiveSearch range:replaceRange];
if (replaceCount >=1) {
// update the textView's text
textView.text = updatedText;
// leave cursor at end of inserted text
endRange.location = text.length+ replaceCount*100000000; // length diff of "hello" and "hi" is 3 characters
// endRange.location;
NSRange h= endRange;
textView.selectedRange= h;
[updatedText release];
return NO;
}
[updatedText release];
return YES;
}
如果我使用這種方法,它只讀取一個字符,並用空格替換該字符。
非常感謝它的工作。 ..你好哦....但我有另一個問題,當我按下按鈕它顯示「அ」,但是當我按下aa它不顯示「ஆ」。它顯示「அஅ」所以該怎麼辦。 – dhaya
以相同的順序添加行,我寫他們先替換@「aa」,然後「a」,也請不要忘記upvote或/和接受答案,如果它有幫助:) –
我使用像...我沒有得到答案int replaceCount = [updatedText replaceOccurrencesOfString:@「aa」withString:@「ஆ」options:NSCaseInsensitiveSearch range:NSMakeRange(0,updatedText.length)] || [updatedText replaceOccurrencesOfString:@「a」withString:@「அ」options: NSCaseInsensitiveSearch範圍:NSMakeRange(0,updatedText)]; – dhaya