Below you can see two posts, one with an image, and one without. I placed borders around the views to better understand what is happening. I want the posts without images to be sized smaller than images with posts. I attempted to do this by doing the following:
func setupViews(){ backgroundColor = UIColor.white addSubview(titleLabel) addSubview(iconImageView) addSubview(messageTextView) addSubview(messageImageView) iconImageView.anchor(top: contentView.topAnchor, leading: contentView.leadingAnchor, bottom: nil, trailing: nil, padding: .init(top: 0, left: 8, bottom: 0, right: 0), size: CGSize(width: 44, height: 44)) titleLabel.anchor(top: contentView.topAnchor, leading: iconImageView.trailingAnchor, bottom: nil, trailing: nil, padding: .init(top: 12, left: 8, bottom: 0, right: 0)) messageTextView.anchor(top: titleLabel.bottomAnchor, leading: contentView.leadingAnchor, bottom: nil, trailing: contentView.trailingAnchor, padding: .init(top: 4, left: 10, bottom: 0, right: 10)) messageImageViewHeightConstraint = messageImageView.heightAnchor.constraint(equalToConstant: 200) messageImageViewHeightConstraint.isActive = true messageImageView.anchor(top: messageTextView.bottomAnchor, leading: contentView.leadingAnchor, bottom: contentView.bottomAnchor, trailing: contentView.trailingAnchor, padding: .init(top: 4, left: 10, bottom: 0, right: 10)) }
When the posts are loading, I set the messageImageViewHeightConstraint.constant = 0 if the post does not have an image (optionals). This works to collapse the imageView. Unfortunately as you can see the textView expands to cover the remaining space. I don't want this, I want the contentView's intrinsic size to shrink, and I just want the text to expand to meet the content's intrinsic size. How can I do this? Thank you in advance.
https://stackoverflow.com/questions/67377573/how-can-i-get-the-contentview-to-resize-when-the-content-changes May 04, 2021 at 09:08AM
没有评论:
发表评论