Tarek Ahmed Tarek Ahmed - 1 year ago 164
Swift Question

CosmicMind/Material Textfield's PlaceHolder over left view

Iam using CosmicMind / Material framework trying to put an icon on the left side of the placeholder but the place holder and the image overlay each other here is my code

Txtemail.placeholder = "EmailAdress"
Txtemail.detail = "This EmailAdress is Not Valid"
Txtemail.delegate = self
Txtemail.placeholderNormalColor = Color.black
Txtemail.placeholderActiveColor = Color.pink.base
Txtemail.dividerNormalColor = Color.cyan.base
imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
image = UIImage(named: "email.png");
imageView.image = image;
Txtemail.leftViewMode = UITextFieldViewMode.always
Txtemail.leftView = imageView

and this is the result

enter image description here

enter image description here

what am i doing wrong ? thanks in advance

Answer Source

Try not setting the frame CGRect(x: 0, y: 0, width: 20, height: 20).

Try this:

let leftView = UIImageView()
leftView.image = Icon.phone?.tint(with: Color.blue.base)

textField.leftView = leftView
textField.leftViewMode = .always

Also, try the TextField Sample

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download