简体   繁体   中英

ios - How to auto-resize my view in storyboard? swift 3

I try to auto-resize my view with auto-layout contraints, but I have some errors of Y-position missing. I can't understand what is wrong, I attached my Y-position to the top of the view.

Thanks for your help, here is the screenshot:

约束错误

The problem is that you don't set a fixed height but, if you can, ALWAYS AVOID to put a fixed height for a view. For an app that can fit all screen is better to use different techniques. If don't want to set a fixed height on your view, you have two possible options:

  1. Give to the view a bottom constraint . You should also set the distance between the bottom of your view and the screen (or another object below your view).
  2. Use stackview. If you place your views into a stack view you will be able to autoresize the width and height of your views according to the screen dimension.

You must give a height for the view or construct it's subviews in a way that gives it a height by hooking constraints properly from top to bottom

when you have ay position error it means top, bottom and height issue

and when x it means leading , trailing and width issue

IF you want to create dynamic view drag a vertical UIStackView and give it a height and in runtime add items to it

 self.myStackView.addArrangedSubview(lbl)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM