I have a custom UICollectionViewCell with an oval(with a border) and a label. The cell will change its size based on the size of the label.
Why does my view get warped?
GOAL
1. create a prototype cell in Interface builder with a subclass of UIView with grey border. It has top, bottom, trailing, & leading constraint constant of 4.
2. I add label (not subview of bordered view explained above) with top, bottom, trailing, & leading constraint constant of 8.
3. I add IBOutlet of collectionViewFlowLayout so I can set estimated size (this is for cell resizing).
collectionViewFLowLayout.estimatedItemSize =
UICollectionViewFlowLayoutAutomaticSize
4. The rest is boilerplate like conforming to UICollectionViewDataSource
Here is Custom view class.
class CustomView: UIView {
override func awakeFromNib() {
super.awakeFromNib()
self.layer.borderColor = UIColor.lightGray.cgColor
self.layer.borderWidth = 1
self.layer.cornerRadius = self.frame.height / 2
self.clipsToBounds = true
}
}
self.layer.cornerRadius = self.frame.height / 2
– user6354073