cusmar
cusmar

Reputation: 1913

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:

Contraints error

Upvotes: 1

Views: 4533

Answers (2)

Shehata Gamal
Shehata Gamal

Reputation: 100549

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 a y 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)

Upvotes: 0

Fab
Fab

Reputation: 836

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.

Upvotes: 3

Related Questions