Clarence
Clarence

Reputation: 1943

UIButton leads to UITextField word deletion

I have question on word deleting using a UIButton

E.g. there are 10 letters in the UITextField. I coded by pressing the UIButton so i can have a backspace or delete function to delete letters one by one. However, i only want the user able to delete the last 5 letters among the 10 letters. How can i restrict that?

Here is my code,

-(IBAction)delete:(id)sender{
    if ([display.text length] != 0) {
        display.text = [display.text substringToIndex:[display.text length]-1];
    }

Upvotes: 0

Views: 56

Answers (1)

Sri Tirupathi Raju
Sri Tirupathi Raju

Reputation: 819

if ([display.text length] > 5) {
    display.text = [display.text substringToIndex:[display.text length]-1];
}

Upvotes: 2

Related Questions