UITextView inputView

旧时模样 提交于 2019-11-30 05:18:23

Assuming your keyboard has some buttons, why cant you just set a selector for your keys, and append to the textViews text when each button is clicked, I have done this an it works fine...Here is the method that actually does the "writing" to the UITextView, this method is part of a custom protocol defined by the inputView and is called on the delegate whenever a button is pressed, hope it helps, note: i submit ret when the return key is pushed and <- when backspace is pushed.

-(void)userDidInputString:(NSString*)s
{
    NSRange r=padView.textView.selectedRange; 
    if([s isEqualToString:@"ret"])
        s=@"\n";
    if([s isEqualToString:@"<-"])
    {
        NSString *text=padView.textView.text;   
        if(r.location>0)
        {
            r.location=r.location-1;
            r.length+=1;
        }
                [padView.textView setScrollEnabled:YES];
        padView.textView.text=[text stringByReplacingCharactersInRange:r   withString:@""];
        [padView.textView setScrollEnabled:NO];
        r.length=0;
        [padView.textView setSelectedRange:r];
        [note setNoteText:padView.textView.text];

    }
    else {
        NSString *text=padView.textView.text;   

        [padView.textView setScrollEnabled:YES];
        padView.textView.text=[text stringByReplacingCharactersInRange:r withString:s];
                [padView.textView setScrollEnabled:NO];
        r.location=r.location+[s length];
        //whenever you modify the text by setting the UITextViews text property it resets the cursor to the end of the text view, we have this line below to go back to where the user left off
        [padView.textView setSelectedRange:r];


            }


}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!