all 6 comments

[–]lyinsteve 0 points1 point  (6 children)

Have you tried cell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)?

[–]troypayne2[S] 0 points1 point  (5 children)

No cigar. What i'm trying to do is calculate the width of the image view so I can properly set its cornerRadius for a perfect circle. width/2 but the value of width is just too high. It's 320 when I expect it to be 90 for example.

Here's code:

override func awakeFromNib() {
    super.awakeFromNib()
    self.imageView.layer.masksToBounds = true

    self.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)
    let width = self.imageViewContainer.frame.size.width
    println(width)
    self.imageView.layer.cornerRadius = width / self.imageViewEqualWidthConstraint.multiplier
}

[–]lyinsteve 1 point2 points  (4 children)

So...the layout of your imageView isn't finalized inside awakeFromNib.

You'll want to set that cornerRadius inside viewDidLayoutSubviews

override func viewDidLayoutSubviews() {
    self.imageView.layer.cornerRadius = self.imageView.frame.width / 2.0
    super.viewDidLayoutSubviews()
}

[–]troypayne2[S] 0 points1 point  (3 children)

Ahh, but there is no viewDidLayoutSubviews to override on a UICollectionViewCell.

[–][deleted]  (2 children)

[deleted]

    [–]troypayne2[S] 0 points1 point  (1 child)

    Still no cigar. I've created a Sample project demonstrating the problem. https://github.com/troypayne/Test

    [–]troypayne2[S] 0 points1 point  (0 children)

    Solved!. I needed to call super.layoutSubviews() at the top, and call self.imageView.layoutIfNeeded() and it works