UITextView inputView

后端 未结 1 1788
情书的邮戳
情书的邮戳 2020-12-29 13:44

I\'m making a custom input method for the iPad, I want to be able to replace the system keyboard with my input method and enter text via that input method.

According

相关标签:
1条回答
  • 2020-12-29 14:29

    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];
    
    
                }
    
    
    }
    
    0 讨论(0)
提交回复
热议问题