How to Resize UIView for universal application usi

2019-08-13 06:03发布

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 ?

stupids uiviews, resize yourselves please

4条回答
够拽才男人
2楼-- · 2019-08-13 06:31

You can do it with Autolayout and Size classes. Here are links to great tutorials:

Autolayouts

Size Classes

查看更多
老娘就宠你
3楼-- · 2019-08-13 06:38

If These are UIViews. Then you can do the following:

  1. Select all the views at once:

enter image description here

Try this. And let me know if some issue arise.

Hope this can help.

查看更多
Fickle 薄情
4楼-- · 2019-08-13 06:39

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.

查看更多
趁早两清
5楼-- · 2019-08-13 06:45

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

查看更多
登录 后发表回答