3

我想要类似泰米尔语键盘

功能:按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;     
}

如果我使用这种方法,它只会读取一个字符,并用空格替换那个字符。

4

1 回答 1

1

如果要将所有“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)];
于 2012-06-11T13:04:25.763 回答