美文网首页
UITextView 打入中文时,输入拼音会调用 textVie

UITextView 打入中文时,输入拼音会调用 textVie

作者: 炸街程序猿 | 来源:发表于2023-02-23 17:02 被阅读0次

做项目的时候需要用到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;

}

相关文章

网友评论

      本文标题:UITextView 打入中文时,输入拼音会调用 textVie

      本文链接:https://www.haomeiwen.com/subject/bmctldtx.html