I have a somewhat basic subclassed UICollectionView Cell. I want to add a UIImageView to it, so every cell displays an image.
The image is displaying properly if I add explicit values to x:y:width:height, but I can't use self.contentView.frame.width
to determine the size of the Collection View cell (for placing the image on the x axis)
class SubclassedCell: UICollectionViewCell {
var myImageView: UIImageView!
required init?(coder aDecoder: NSCoder) {
super.init(coder:aDecoder)
myImageView = UIImageView(frame: CGRect(x: (self.frame.width - 10.0), y: 50.0, width: 20.0, height: 20.0))
myImageView.image = UIImage(named: "JustinBieber")
self.contentView.addSubview(myImageView)
}
}
In the above, (self.contentView.frame.width - 10.0)
is not getting the size of the collection view cell, so the image does not display at all. If I explicitly put in a value for x, say 0, it shows.
How can I determine the size (width) of the subclassed collection view cell?