Berk Kaya Berk Kaya - 1 year ago 56
Swift Question

UITextField with user text + static mark

I have an UITextField which user sets its luggage weight as numbers in TextField. I want to set that textfields value with weight mark (for ex 10 KG which comes from user settings) so whatever user types, there will be KG mark at the end of its textfield. Is there any way for it?


do like

initially clear the value when begin start

func textFieldShouldBeginEditing(textField: UITextField) {
textField.text = ""

when editing is over append the kg

func textFieldDidEndEditing(textField: UITextField) {
yourTextfieldName.text = "\(textField.text!) KG"


 func textFieldDidEndEditing(textField: UITextField) 
if !textField.text!.rangeOfString("KG").location != NSNotFound {
self.textField.text = textField.text!.stringByAppendingString("KG")