0

I am trying to size my UICollectionViewCell for the proper size of a given label, and I also want to add some padding so the label doesn't look suffocated. This is my class I'm using for the CollectionViewCell:

class BarTypeCell: UICollectionViewCell {
    
    @IBOutlet weak var nameLabel: SizeToFit!
    
    override func awakeFromNib() {
        self.frame = CGRect(x: self.frame.origin.x, y: self.frame.origin.y, width: self.nameLabel.frame.width + 10, height: self.nameLabel.frame.height + 10)
        self.layer.borderColor = UIColor.label.cgColor
        self.layer.borderWidth = 1.0
        self.layer.cornerRadius = 5.0
        self.clipsToBounds = true
    }
}

and this is what the output looks like: enter image description here

How can I give the cell labels proper padding from the border?

Noah Iarrobino
  • 1,435
  • 1
  • 10
  • 31

1 Answers1

0

You may need to use UICollectionViewDelegateFlowLayout. Pointers at UICollectionView Custom Cell to fill width In Swift

IFTTT
  • 186
  • 6