Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView is resized using auto layout but getting its frame size on runtime is not correct ios

When i am placing view of frame size (0.0,0.0,320.0,435.0) applying auto layout it appears proper in iphone 5 (4 inch) and when i am running in iphone 4s it appears proper due to autolayout but when i am fetching value of its frame after execution during run time it appears "(0.0,0.0,320.0,435.0)" I cannot get size which have change after applying auto layout in iphone 4s? I want to get size because using that size i can set programmatically size of custom view created.

like image 277
Zalak Patel Avatar asked Dec 03 '14 12:12

Zalak Patel


People also ask

What is intrinsic content size IOS?

Intrinsic content size is information that a view has about how big it should be based on what it displays. For example, a label's intrinsic content size is based on how much text it is displaying. In your case, the image view's intrinsic content size is the size of the image that you selected.

How does a view's intrinsic content size aid in auto layout?

In general, the intrinsic content size simplifies the layout, reducing the number of constraints you need. However, using the intrinsic content size often requires setting the view's content-hugging and compression-resistance (CHCR) priorities, which can add additional complications.

When should I use layoutSubviews?

layoutSubviews() The system calls this method whenever it needs to recalculate the frames of views, so you should override it when you want to set frames and specify positioning and sizing. However, you should never call this explicitly when your view hierarchy requires a layout refresh.

What is Autolayout in Swift?

Auto Layout constraints allow us to create views that dynamically adjust to different size classes and positions. The constraints will make sure that your views adjust to any size changes without having to manually update frames or positions.


1 Answers

Before your "getting real size code", insert the following code:

yourView.setNeedsLayout()
yourView.layoutIfNeeded()
like image 58
Allen Avatar answered Sep 29 '22 19:09

Allen