Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Can't change a width in a horizontal stackview

I'm starting with iOS app and creating a table view. In my table I have a cell like this.

enter image description here

Now I need to center the horizontal stackview with stars vertically and horizontally. This stackview has fixed width and height.

It have to look like this.

enter image description here

For this I put it in another horizontal stackview. I tried to add the same constraints to it as you see for the label

The problem is that this external stackview does not stretch like a label. I also see that it's width and height are greyed out, I cannot change them. Why?

enter image description here

like image 556
Vitalii Avatar asked Mar 20 '18 15:03

Vitalii


1 Answers

There are many ways to autolayout this.

I think you should gain a better understanding of StackViews for future usage. I recommend reading on these resources:

  • https://developer.apple.com/documentation/uikit/uistackview
  • https://www.raywenderlich.com/160646/uistackview-tutorial-introducing-stack-views-2

In order to achieve what you need:

  1. Use only 1 horizontal StackView containing the stars. Constraint the stackview to the label by center horizontally.

  2. Use 2 StackViews and keep your constraints. Outer stackview, change it to vertical axis and center alignment.

Method 2 Image in Attributes Inspector (cmd + option + 4):

Attributes Inspector1

like image 144
Errol Avatar answered Oct 17 '22 06:10

Errol