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.

3
  • 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. Commented Aug 20, 2017 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! Commented Aug 20, 2017 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. Commented Aug 21, 2017 at 14:55

1 Answer 1

1

Set a height value to the UIStackView :)

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

2 Comments

i made a mistake in my comment before but can't edit... i set .translatesAutoresizingMaskIntoConstraints = true not false!
Not sure how to fix that. Leaving this comment here though is good :)

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.