0

I have a UIView that changes height based on the amount of content in it. It's basically a list of tags. I am not sure how to adjust the row height based on the height of the tagView. Also when it goes to a smaller iPhone screen the height of the tagView also adjusts. I know how to work with images as this example demonstrates very well: How to resize UIImageView based on UIImage's size/ratio in Swift 3?. But I am not sure how to work with a tagView which is a type of UIView.

I am using UITableViewAutomaticDimension but this is not affecting the cell which contains the tags.

As you can see below the content just goes over the cell:

enter image description here

Chace
  • 561
  • 10
  • 28
  • How do you add tag views to cell? – Mohammad Zaid Pathan Jan 04 '18 at 14:49
  • Same way I add any other UIView element to a cell like a photo etc. By defining it and adding the constraints. – Chace Jan 04 '18 at 14:50
  • Have you set `tableView.estimatedRowHeight = 80.0(any value)` and `tableView.rowHeight = UITableViewAutomaticDimension` both? [This](https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithSelf-SizingTableViewCells.html) might be helpful. – Mohammad Zaid Pathan Jan 04 '18 at 15:02
  • Ok I got it to work, I was not setting it up properly. But the issue now is the padding on the bottom seems really large the more tags I have – Chace Jan 04 '18 at 15:05
  • Great, What was the issue? Also, I would suggest change adding view and replace it with `UICollectionView` if possible. – Mohammad Zaid Pathan Jan 04 '18 at 15:07
  • Quite a minor issue I was calling `addSubview(tagView)` instead of `contentView.addSubview(tagView)`. I'm not sure why you're suggesting I use a `UICollectionView`? – Chace Jan 04 '18 at 15:10
  • So that easily you can add cells, instead of adding multiple `UIView`s. – Mohammad Zaid Pathan Jan 04 '18 at 15:12
  • I see, this doesn't seem to be an issue as for the tags I'm using a library which does all of this for me. It wraps inside a dynamic view. That's why I asked this question. But I am now having problems where there is a large space at the bottom of my tags when I add more. – Chace Jan 04 '18 at 15:14
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/162526/discussion-between-mninety5-and-zaid-pathan). – Chace Jan 04 '18 at 15:16

0 Answers0