带有用户文本+静态标记的 UITextField

UITextField with user text + static mark

我有一个 UITextField,用户将其行李重量设置为 TextField 中的数字。我想设置带有重量标记的文本字段值(例如来自用户设置的 10 KG),因此无论用户类型如何,其文本字段的末尾都会有 KG 标记。有什么办法吗?

您可以在 UITextField 旁边放置一个 "Label"。

然后只需将标签的文本更改为用户选择的内容即可。

或者(但我不知道这是否有效),尝试从文本字段中获取文本,将单位(作为字符串)添加到文本字段中的字符串中。

喜欢

begin开始时初始清除值

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

当编辑结束时追加公斤

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

选择-2

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