After two days struggling with this, I come to solution that can trick this. I'm creating stackView
that contain of UITextField
. I create array for temporary text that filled the UITextField
. Then, when the UITextField is filled by some character, I programmatically add UIImage
. In my code, will look like this.
let chars = Array(shieldString)
for (index, char) in chars.enumerated() {
if let tmp = self.stackView.arrangedSubviews[index] as? UITextField {
let imageView = UIImageView(image: UIImage(named: "dotImage")!)
imageView.frame = CGRect(x: 0, y: 0, width: 28, height: 28)
imageView.center = CGPoint(x: tmp.frame.size.width / 2, y: tmp.frame.size.height / 2)
imageView.tag = 100
tmp.addSubview(imageView)
}
}
And for clear the Image, just using this. I use tag so I can delete specific subview.
for ele in self.stackView.arrangedSubviews {
if let viewWithTag = self.view.viewWithTag(100) {
viewWithTag.removeFromSuperview()
}
}
I know that this not custom class, and quiet messy, but if you in a rush like me, this probably will save you.