Reputation: 7050
I am creating subView with UIButtons. I want to delete text from UITextField like keyboard's backspace button with UIButton. In Keyboard's backspace button,once clicked , it's just delete one word. Like that, i want to do with UIButton. How can i do that?
Upvotes: 0
Views: 665
Reputation: 29
you can use the UILongPressGestureRecognizer event for button, in that on start of gesture we can clear the text and end it on gesture end. for code go through the below link
http://iossubbu.blogspot.in/2013/12/ios-custom-backspace-button-to-clear.html
Upvotes: 2
Reputation: 8147
Get the UITextField
's text
property, remove the last character and set the new string back to the UITextField
.
- (void)someButtonPressed:(id)sender {
NSString *text = [myTextField text];
text = [text substringToIndex:[text length] - 1];
[myTextField setText:text];
}
Upvotes: 1