作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想使用泰米尔语键盘
功能:按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;
}
如果我使用此方法,它只会读取一个字符并将该字符替换为空格。
最佳答案
如果你想把所有的“a”替换成“அ”和“aa”到“ஆ”请执行下列操作第一次测试“aa”
//this will repleace all of "aa"
int replaceCount = [updatedText replaceOccurrencesOfString:@"aa" withString:@"ஆ" options:NSCaseInsensitiveSearch range:[NSMakeRange(0, updatedText.length)];
//this will repleace all of "a"
int replaceCount = [updatedText replaceOccurrencesOfString:@"a" withString:@"அ" options:NSCaseInsensitiveSearch range:[NSMakeRange(0, updatedText.length)];
关于iphone - 如何在 uitextview 文本中添加自定义语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10980462/
我是一名优秀的程序员,十分优秀!