做項目的時候需要用到UITextView
輸入法設置為中文時,我想輸入中文“有”,我輸入一個字母y的時候,一下回調會被調用
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
和
- (void)textViewDidChange:(UITextView *)textView
目前的解決方案是用以下方式做適配
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
if (textView.text.length !=0) {
int a = [text characterAtIndex:0];
if( a > 0x4e00 && a < 0x9fff)
{
NSLog(@"漢字");//做相應適配
}
else
{
NSLog(@"english");//做相應適配
}
}
returnYES;
}
如有疑問可以進IOS中高級開發群:118623167 和大家交流