Utku Dalmaz
Utku Dalmaz

Reputation: 10192

Hiding element space without height constraint

enter image description here

This is a reuseable tableview cell. I want to hide 3. UILabel from the top, both the element and its space when it has no data.

I can't create a height constraint of it because I need to use it multiline depends on the text.

if release.post.isEmpty {

    cell.label3.isHidden = true

} else {

    cell.label3.isHidden = false

}

So how can I hide its space without a height constraint?

Upvotes: 0

Views: 147

Answers (2)

Utku Dalmaz
Utku Dalmaz

Reputation: 10192

I fixed this by dynamically adding the constraint

cell.match.translatesAutoresizingMaskIntoConstraints = false
                cell.match.constraints.forEach { (constraint) in
                       if constraint.firstAttribute == .height
                       {
                        constraint.constant = release.post.height(withConstrainedWidth: cell.match.frame.width, font: UIFont.preferredFont(forTextStyle: UIFont.TextStyle.subheadline)) + 15
                       }
                   }

Upvotes: 0

Devanshi Modha
Devanshi Modha

Reputation: 359

You can use the stack view and then hide the required objects i.e label or image. Remember to give the proper constraints to the stack view and select the required properties.

Upvotes: 1

Related Questions