开发者

Custom keyboard iphone , having problem with backspace button in UITextView

开发者 https://www.devze.com 2022-12-24 06:11 出处:网络
Check this code (My Custom Keyboard): -(IBAction) updateTextBackSpace:(id)sender { if([txtview.text length]>0)

Check this code (My Custom Keyboard):

-(IBAction) updateTextBackSpace:(id)sender
{
    if([txtview.text length]>0)
    {
        NSString *deletedLastCharString = [txtview.text substringToIndex:([txtview.text length]-1)];
        [txtview setText:deletedLastCharString];
    }
    else
    {
        return nil;
    }
}  

The thing is that I can't figure out h开发者_如何学运维ow to change this code so that. I can erase any text in any give line at the cursor, the backspace starts to erase from end of the line. I should be able to erase(backspace) from the cursor location.


replace this

NSString *deletedLastCharString = [txtview.text substringToIndex:([txtview.text length]-1)];

with

NSRange range  = [txtview selectedRange];
NSString *deletedLastCharString = [txtview.text substringToIndex:([range.location]-1)];
0

精彩评论

暂无评论...
验证码 换一张
取 消