-1

So, I understand that to get the height of the view in Swift I can do:

viewHeight = view.frame.height

But how can I do this outside of that Swift file? I have another swift file which is a class and I need to somehow access the view height there.

I was thinking of so far:

viewHeight = MyViewController.view...

but it doesn't look like it will work.

Any ideas? All I am looking for is the height of the screen view, not any specific view. Thanks

George_E -old
  • 188
  • 1
  • 3
  • 17

1 Answers1

1

Try this

let height = UIScreen.main.bounds.size.height
Lenin
  • 675
  • 6
  • 17
  • what is the problem with this. – Lenin Mar 25 '18 at 12:57
  • Just realised I forgot UIKit – George_E -old Mar 25 '18 at 12:58
  • This means it would get the screen height not a specific view height. The funny thing that @George_E accepted which means that what is he looking for but he didn't mentioned that in the question! – Ahmad F Mar 25 '18 at 13:02
  • @AhmadF I'm new, and aren't view heights always the same anyway? – George_E -old Mar 25 '18 at 13:03
  • @George_E if you mean the view controllers main view of course they are! they are the height of the device, which means you don't even have to get the main view of another view controller. But logically I assumed that you are asking for a specific view not the main one, since it's obviously the screen's height. – Ahmad F Mar 25 '18 at 13:06