user2892270
user2892270

Reputation: 305

How to get the real size of a view with auto layout?

I have a view in interface builder. I set the width as 600, height as 400. Then I added some constraints to make sure it display correctly on different screen-size devices. The constraints are like: 'trailing space to superview:0, leading space to superview: 0....' Here superview is the main view of the ViewController.

When simulating the app, the view displayed well, and I printed out the size of the view. The printed results show that both the frame and the bounds are still (600, 400). I thought the width of the view would equal to my screen width. What is the problem here?

I'm running it on an iPhone6. I layout the view in interface builder. The test code is

println("bounds width:\(myView.bounds.width), height:\(myView.bounds.height)")
println("frame width:\(myView.frame.width), height:\(myView.frame.height)")

Upvotes: 0

Views: 714

Answers (1)

Leo
Leo

Reputation: 24714

You can check the size in viewDidLayoutSubviews,at this time,your constraints have been applied to your view

Upvotes: 1

Related Questions