Oviya Arasu Oviya Arasu - 4 months ago 11
iOS Question

Inserting UIView into background and having textfield/button appear on top (SWIFT)

I want to create a login page in which the image I have fills up the entire page. I was able to accomplish this by doing

let imageView = UIImageView(frame: self.view.bounds)
imageView.image = UIImage(named: "background")

However, I also have textfields and buttons on my storyboard which I created outlets for on my swift file. When I insert that code into the viewDidLoad() function, the textfields and login button go underneath the image rather than appear over the image. I'm not exactly sure how to get the login page text fields/buttons to appear over the UIImageView rather than be hidden underneath. The code I have for that is written outside the viewDidLoad


@IBOutlet var usernameTextField: UITextField!
@IBOutlet var passwordTextField: UITextField!

@IBAction func loginPressed() {
let username = usernameTextField.text
let password = passwordTextField.text


Try this:


This method moves the specified view to the beginning of the array of views in the subviews property.