I did a UIView with UIView embedded inside. I used constraints to get a decent UIView but it is not yet working the way I want even though the result is okay.
I would like to get the same results I have on the iPhone 4.7 inch into the iPhone 5.5 inch and the 4 inch.
For that, I think I need to resize the blue UIViews
but I have no clue how to make them auto resize from storyboard
nor programmaticaly. I remember a long time ago, I did it for an Android Application and it was easy, I just needed to give a % bigger or lower
.
Is there a way to do it with iOS ?
![](https://www.manongdao.com/static/images/pcload.jpg)
If These are UIViews
. Then you can do the following:
- Select all the views at once:
![](https://www.manongdao.com/static/images/pcload.jpg)
Try this. And let me know if some issue arise.
Hope this can help.
I believe ismail's comment is correct, size classes are the correct way to do this in storyboard.
If you are looking for a more programmatic solution, you can implement the sizeForItemAtIndexPath method on UICollectionViewDelegateFlowLayout
, for example, you could calculate the width of each device and return the right proportions for each cell using the method mentioned. Basic example:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width:10, height:10)
}
Be sure to account for your collection view spacing and section insets when calculating your widths and heights.
Apple stated that simply selecting all views in the scene, and hitting "Add Missing Constraints" or "Reset to Suggested Constraints." will solve the majority of auto-layout issues. Give that a shot first and foremost. (I'm looking for the source now, will edit answer with it soon).
Then, check out this Apple document on resolving auto-layout issues. It is a short article that will help you understand how to debug what you are trying to do:
https://developer.apple.com/library/ios/recipes/xcode_help-IB_auto_layout/chapters/ResolvinganItemsLayoutIssues.html
You can do it with Autolayout and Size classes. Here are links to great tutorials:
Autolayouts
Size Classes