UIView Issue in swift2.0

76 Views Asked by At

I have created a uiview in storyboard and have placed it in some random point(autoLayout not applied) . Now in viewDidLoad() Im trying to place it at the center of the screen. But its not moving from that place and replaced at center Why? is this because of some order viewController Life Cycle ? But when I Create a UIView programmatically and placed it in center it works .??

class ViewController: UIViewController {

    @IBOutlet weak var view1: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()

        view1.center = view.center

    }



}
2

There are 2 best solutions below

0
Mundi On

Your guess is correct. You need to do this in viewWillAppear. viewWillLayoutSubviews is also a good place to put this.

0
Mohsin Qureshi On

use viewDidLayoutSubviews

- (void) viewDidLayoutSubviews {
    self.view1.center = self.view.center 

}