简体   繁体   中英

UILabel and UITextField edit character

I m doing a anagram type of task in iOS. In this case i need a solution,

For ex:

NSString* quest = @"SATCK";
labelQuestion.text = quest;

I have a UITextField to type the answer. The correct answer is "STACK". The user will type this to the UITextFiled. For ex: When the user types "S" in the textfield i need to remove the character "S" from the UILabel, similarly if he deletes the character "S" in textField I need to bring back the "S" in UILabel. This should happen for all the characters user types. If the user types "STACK" in textField i need to hide S, T, A, C, K characters from the UILabel one by one. HOw can I achieve this.

Thanks

You need to set a delegate object that conforms to the " UITextFieldDelegate " protocol.

Then you can catch characters being typed into your text field via [UITextFieldDelegate textField:shouldChangeCharactersInRange:replacementString:] .

In that method in your delegate object, you can write code to detect what characters are being typed in and you can subtract those letters from your label (or re-add them if the characters were deleted from the text field).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM