2

I have a simple question, how do I find the height of the View Controller programmatically when I have it set to freeform?

I want to do something like:

let viewControllerHeight = viewController.contentSize.height

This is what I'm trying to find

Also, how do I post an image on here without it being a link?

vacawama
  • 150,663
  • 30
  • 266
  • 294
Ken
  • 1,155
  • 2
  • 19
  • 36

4 Answers4

5

There's no such thing as UIViewController height because this class is only a CONTROLLER of a view. You can get the height of its view in a very simple way

let height = viewController.view.frame.size.height

Please note that this value may be incorrect in viewDidLoad and you need to check it later. Find out more

Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161
1

The simulated size affects the size of the UIViewController’s view in the Storyboard. If you access self.view.frame.size.height in viewDidLoad() you will see that value. After the view appears, in viewDidAppear(), the frame of the view will be adjusted for the screen size and orientation of the device your app is running on.

Until you have enough rep, your pictures show as links. You can fix this by editing your question or answer and adding a ! before the link usage like I did for your question.

vacawama
  • 150,663
  • 30
  • 266
  • 294
0

Try this code:

  let viewControllerHeight = viewController.view.frame.size.height
Andrew21111
  • 868
  • 8
  • 17
0

Actually the safe area height is your viewController height. So you can find it like this

let guide = self.view.safeAreaLayoutGuide
let height = guide.layoutFrame.size.height

Please have a look on this Link

Asad Ali Choudhry
  • 4,985
  • 4
  • 31
  • 36