Need constraints for y position, height - Auto layout Storyboard
Asked Answered
O

2

6

First let me tell that I have gone through multiple same kind of questions available in Stack Overflow but neither of them helped me.

So I created new question for discussing my problem.

I am beginner with iOS programming and with layout making in Storyboard so daily facing few problem in designing. With this problem, I already spent my 2 days but may be its really easy for an expert person to help me in this problem.

I was getting red warning in layout for need constraints for y position, height and any how I want to resolve this. Following image will make you more clear regarding this:

enter image description here

Specifically I was getting problem in video view and button below that regarding y position constraints.

enter image description here

So please suggest me, how to solve this problem? I was getting same problem multiple times when I was making layout so if I learn this solution then it will be big relief for me.

Orgel answered 2/4, 2018 at 18:24 Comment(7)
This seems pretty straight-forward... Your VideoView has no Height constraint, and has no Y-position constraint, and your Del 1 button has no Y-Position constraint. You can click on the Red-error-circle, and allow Interface Builder to add suggested missing constraints. That may or may not give you exactly what you want, but may be a good place to start.Eurus
I already tried with adding height constraint then its asking for y position constraint - so shall I require to add both ??Orgel
Also height constraints for me will not work at all because its can't able to resize based on resolution.Orgel
Without using height constraints anybody can solve above issue??Orgel
Yes, you also need to give it a y-position constraint (otherwise, how is auto-layout to know where it should go?). If you need the view's height to change based on resolution, then you can give it a ratio of width to height.Eurus
This is pretty basic auto-layout... I expect you would find it helpful to go through the documentation - starting here: developer.apple.com/library/content/documentation/…Eurus
You need height and y position constraint. You can also set height (or width) proportional to screen height (or width). For doing this control drag from your video view to main view and select equal height. Then select this equal height constraint in Size inspector and change multiplier to for example 0.5 if you want height equal to half of the height of screenNimbostratus
H
1

You need to set the VideoView Height constraint.

Steps:

  1. Select the VideoView.

  2. Click in "Add New Constraints" next to "Align" and after "Resolve Auto Layout Issues" option.

  3. Set the height constant you want.

  4. Check the height box.

  5. You also need set the Y position, because the VideoView don't know what is below and above. So, click the top constraint to make it look red, set the space that you need between your topView and the VideoView (in this case of my image example: 0)evidency of top constraint

  6. Click "Add 1 constraint"

Hyalite answered 2/4, 2018 at 19:11 Comment(1)
It also need y position in addition to heightNimbostratus
H
1

You can give the constraints in the different ways as per your requirement:

1) Select your video view

2) Add new constraint and add the top constraint (Constraint between your Video view and top view, in your case the view with text surfa)

3) Select bottom constraint (if bottom buttons hight is fixed)

or

3) Select the height constraint (if you want to fix your video view height)

or

3) You can give the aspect ratio to video view (In this situation your view's height will be change as per the screen size)

Hope this will be helpful to you.

Hannahhannan answered 3/4, 2018 at 13:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.