DevStarlight
DevStarlight

Reputation: 804

UIView returns the same size depending of the device

I have a dynamic UIView based on the height 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 UIView depending of the device?

Upvotes: 1

Views: 67

Answers (1)

Christoph
Christoph

Reputation: 722

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.

Upvotes: 1

Related Questions