Dhaval H. Nena
Dhaval H. Nena

Reputation: 4160

how to get actual size of custom view which is loaded from nib ios

I am loading a custom view from xib and adding it in my main view. I need to get the actual size of that view once it is loaded and added in the main view.

I am using autolayout for that custom view to place their sub views.

Problem is it is showing the default size which I have set in the xib. I need device specific size for that view. Please help me how to do that. Thanks.

Upvotes: 2

Views: 941

Answers (1)

haluzak
haluzak

Reputation: 1143

After you add your custom view loaded from xib to your main view, you should add constraints from main view to your custom view so that the custom view knows how to layout itself. Then you should call self.customView.layoutIfNeeded() and after the layout has been done you can get its size simply with self.customView.frame.size.

Upvotes: 2

Related Questions