Created
July 12, 2019 07:47
-
-
Save giusecapo/f8b02b7e6242b82ed1bf5e447a3030c6 to your computer and use it in GitHub Desktop.
Custom View for Self-sizing cell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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