vendredi 31 juillet 2015

Modifying layer properties for contents of collection view cell

I'm having mixed results when modifying the layer properties of an UIImageView. In a UICollectionView, I have UICollectionViewCells that have a single UIImageView in them. I want those images to look like circles, thus, in my UICollectionViewCell subclass, I override layoutSubviews and placed my code there, like so:

override func layoutSubviews() {
  super.layoutSubviews()
  image.layer.cornerRadius = CGRectGetWidth(image.bounds) / 2
  image.layer.masksToBounds = true
}

However, I was getting unreliable results. Sometimes, the images are perfect circles (as intended), but sometimes they're squares with rounded edges, that may or may not become circles if you scroll through the collectionView.

Where is the best place to put this code?

Aucun commentaire:

Enregistrer un commentaire