DevStarlight DevStarlight - 3 years ago 180
iOS Question

UIView returns the same size depending of the device

I have a dynamic UIView based on the

of a superView by using a multiplier (in my case 0.125 the height of the superview).

For any reason, when I want to recover the value of the view:

let rangeSliderHeight = playerView.bounds.size.height * 0.5

I get the same size with my iPhone 5 and my iPad, even though visually, on iPad is much more big than iPhone.

There's no autolayout option to define custom rules for iPads or iPhones for this case, since the library I use builds the element from code.

Is there any posibility to get the real size of the
depending of the device?

Answer Source

Call playerView.bounds.size.height in viewDidLayoutSubviews() instead of viewDidLoad(). At that point the views will have been laid out and you can retrieve the actual size.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download