iosswiftautolayoutui-design

How top Stop arranged Subview Clipping in StackView


I have three arranged subviews inside stackView like this: my "Rec" Label and "00:00:00" Label have their bottom and top portion clipped. i don not want that

a red horizontal StackView with a Square red view , a record label and a timer label where Record Label and Timer Label are clipped by a little bit from bottom and top

Constraints For square red View: Height = 10px Width = 10px

Constraints For "Rec" and "00:00:00" label - None

Constraints for StackView:' center vertically In Safe Area trailing Space to safe Area 30px

Please ignore the white background view, its there just so i could show the clipping of my labels..it does not have any constraint.

i would like a way where stackViews height gets decided by the intrinsic content size of "Rec" or "00:00:00" label. whichever has bigger height.


Solution

  • You likely need to specify the alignment for your stackView. If you're using a storyboard, check the Attributes Inspector for your stackView. Specifying "Center" will likely do what you need. Just don't specify "Fill".

    enter image description here

    If you're configuring your stackView programatically, then all you need to do is set the alignment property this way:

    stackView.alignment = .center