My best guess to achieve this using image. You can simply add image on your UITextField's subview.
func addImageToTextField(txtPin : UITextField)
{
let imageView = UIImageView();
let image = UIImage(named: "darkImage.png");
imageView.image = image;
imageView.frame = CGRect(x: 0, y: 0, width: txtPin.frame.width, height: txtPin.frame.height)
txtPin.addSubview(imageView)
}
And call this method from textFieldshouldChangeCharactersInRange
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
textField.textColor = UIColor.clearColor()
if (!string.isEmpty) {
self.addImageToTextField(textField)
}
Similarly you can do the same if user hits back button to clear the textfield
I have done this and works like a charm for me. Cheers !! happy coding.