Design UIView subclass auto layout with custom siz

2019-07-25 12:24发布

问题:

I have an UIView subclass with its layout in a .xib file. I set the size to freeform and the dimensions to something like 200 x 300.

How can I set different dimensions for iPad so the "View as" option correctly show a preview of how it would look like?

Or, can this be achieved in a different way? Maybe using a storyboard instead of a xib file?

回答1:

Similar kind of feature I did last week. I had an xib file and that I was using as a collectionView item. Through interface builder it cannot be differed. I achieved this programmatically. You can change the size of UIView as required.

Let me know if you have any query.



回答2:

Certainly, you can make it compatible with Auto Layout and you can use IBDesignable to do visual layout in Interface Builder.

I have a couple examples - including loading custom views from XIB files - here: https://github.com/DonMag/IBDesignInspect