1

I am attempting to use the CardTableView, and I am able to render cards from my API call. However, I am trying to load multiple UILabels and lay them out using UIStackViews within the content area of the card. The toolbar and bottom bar already have icons and will be used appropriately. When I embed the stackView and dont set translatesAutoresizingMaskIntoConstraints = false the cards are spaced correctly, as shown in this picture: Correct spacing of cards, no stack views rendering

However there is none of my labels visible. The following picture shows that when i set translatesAutoresizingMaskIntoConstraints = false the labels show up, but the card spacing is all ruined. stack views render, but spacing is off

Here is my method for preparing the Content:

private func prepareCardContent() {
    contentLabelStackView = UIStackView()
    contentLabelStackView.axis = UILayoutConstraintAxis.vertical
    contentLabelStackView.distribution = UIStackViewDistribution.equalSpacing
    contentLabelStackView.alignment = UIStackViewAlignment.leading
    contentLabelStackView.spacing = 0
    contentLabelStackView.addArrangedSubview(invitedLabel)
    contentLabelStackView.addArrangedSubview(teeUpTitle)
     contentLabelStackView.translatesAutoresizingMaskIntoConstraints = false
}

And this is my code for preparing the card itself:

private func preparePresenterCard() {
    card.toolbar = toolbar
    card.contentView = contentLabelStackView
    card.contentViewEdgeInsetsPreset = .vertically5
    card.bottomBar = bottomBar
    card.depthPreset = .depth3
    contentView.addSubview(card)
}

I am unsure what is conflicting with the spacing and layout of the cards with using a nested StackView.

kinghenry14
  • 1,187
  • 1
  • 11
  • 34
  • Can you try setting a height to the UIStackView ? The height of the content are is dynamic or fixed, but not necessarily when using AutoLayout. – CosmicMind Aug 20 '17 at 23:33
  • @CosmicMind adding a height worked in conjunction with setting translatesAutoresizingMaskIntoConstraints = false ... thanks! you are always very prompt in answering questions on here! – kinghenry14 Aug 20 '17 at 23:43
  • Thank you :) I am going to post this as the answer so other can find it. When you are free, please mark it correct. – CosmicMind Aug 21 '17 at 14:55

1 Answers1

1

Set a height value to the UIStackView :)

CosmicMind
  • 1,499
  • 1
  • 10
  • 6