Skip to content

Instantly share code, notes, and snippets.

@giusecapo
Created July 12, 2019 07:47
Show Gist options
  • Save giusecapo/f8b02b7e6242b82ed1bf5e447a3030c6 to your computer and use it in GitHub Desktop.
Save giusecapo/f8b02b7e6242b82ed1bf5e447a3030c6 to your computer and use it in GitHub Desktop.
Custom View for Self-sizing cell
import UIKit
class MyCustomCell: UICollectionViewCell {
// mainView is my custom parent view, that contains every other component of the cell
@IBOutlet weak var mainView: UIView!
override func awakeFromNib() {
super.awakeFromNib()
// Add width constraint if you want dynamic height
mainView.translatesAutoresizingMaskIntoConstraints = false
mainView.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.size.width - 40).isActive = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment