0

I am new to iOS Dev and Xcode.

I was trying to practice Auto Layouts in Xcode.

So I was faced with a problem where I wanted to have my score label 20 points from the left side of stack view. So I embedded my label in a UIview element and was able to constraint it to 20 points from left. However, it seems like my UIview element's size has been locked and I am unable to reduce its size.

enter image description here

I want my view element to take same height as my score label which is like 71.5 points but it turns out that minimum height that can be reached for this UIview element is 333.5 as you can see in the image above.

So, how can I reduce its height and did I do anything wrong?

----------- Updated: Here are the constraints -----------

enter image description here

4
  • from stackview it self try to set distribution as fill proportionally, also may I know why you need all elements to be inside stackview ? Commented Jul 8, 2020 at 9:25
  • You're missing a couple constraints, and it looks like you have an erroneous constraint on your white view. Re-do your screen-shot, with all of the arrows expanded (so we can see all of the constraints). Commented Jul 8, 2020 at 13:06
  • @DonMag, thanks for the reply ... I have updated the question to include the constraints. Commented Jul 8, 2020 at 20:59
  • @MohammedGomaa, The distribution was set to fill proportionally, (I have edited the question to include another screenshot) ... Since I needed to stack all these element vertically (such as question text, true, false, progress bar), that's why I thought that stack view will be best to use Commented Jul 8, 2020 at 21:03

1 Answer 1

1

You can delete the MyView.top = top constraint.

Your "Score:" label already has top, leading and trailing constraints to MyView, so add a bottom = Score:.bottom constraint. That will tell the bottom of the white MyView to stick to the bottom of the label.

You may also need to set the Score label's Content Hugging vertical priority to Required (1000).

That should do it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.