Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

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

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

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.

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.