I’m making an attempt to attain beneath picture:
As you’ll be able to see within the picture, when a person varieties a quantity into the textfield, the opposite digits of the quantity nonetheless stand as a placeholder. (000 000 0000)
To do this, I positioned a UILabel within the UITextField.
var placeHolderLabelString = "___ ___ ____"
var placeholderLabel = UILabel()
placeholderLabel.textual content = placeHolderLabelString
placeholderLabel.sizeToFit()
numberInputView.addSubview(placeholderLabel)
placeholderLabel.textColor = .grey
placeholderLabel.font = numberInputView.font
I need to delete every underscore when a person varieties a digit into the textfield. I’ve tried the beneath code:
func textField(_ textField: UITextField, shouldChangeCharactersIn vary: NSRange, replacementString string: String) -> Bool {
let rnd = Vary(vary, in: placeHolderLabelString)!
placeHolderLabelString = placeHolderLabelString.replacingCharacters(in: rnd, with: " ")
placeholderLabel.textual content = placeHolderLabelString
return true
}
However this does not work. It provides an area char to the start of the placeHolderLabelString
, not changing it. How can I try this?