iOS

Simen Anthonsen
Simen Anthonsen


1,097 Points

Posted by Simen Anthonsen

Simen Anthonsen


1,097 Points

Add background image to UITextfield

In order to add a background image to an UITextfield, i have to change the standard border style to square. How do you add a background image without having to change the standard border style?

2 Answers

Martin Foldyna
Martin Foldyna


10,359 Points

Martin Foldyna

Martin Foldyna


10,359 Points

Hello, try to make output of this UITextfield. And than (name of the output).background = UIImage(named: “nameOfTheImage.jpg/png…”);

Simen Anthonsen
Simen Anthonsen


1,097 Points

Simen Anthonsen

Simen Anthonsen


1,097 Points

That´s how I do it, but it only works if i change the border style to square. The picture does not show up with the standard UITextfield border style.

Linus Liang
Linus Liang


1,460 Points

Linus Liang

Linus Liang


1,460 Points

I found a quick workaround where I add a UITextField with backgroundColor set as UIColor.clearColor() as a subview to a UIImageView. You can make the UIImageView have rounded corners by setting UIImageView.layer.cornerRadius.

Posting to the forum is only allowed for members with active accounts.
Please sign in or sign up to post.