I have a custom UICollectionReusableView
with a single label inside: the label has leading, trailing, top and bottom constraints set to 8.
On the controller, I register the cell and then:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return self.sectionSizeForIndex(section)
}
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
let cell = self.collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier: "cellID", forIndexPath: indexPath) as! FooCollectionViewCell
cell.setupLabelWithText("Lorem ipsum")
return cell
}
For debugging reasons, I show both the borders of the cell and the borders of the inner label, with different colors.
Here's what happens: The cell got the right frame, but the inner label seems not update constraints according to its parent view (cell).
On "Debug View Hierarchy", I see that also cell.contentView
doesn't update itself -> I suppose that is this the reason why the label doesn't update.
In cell awake from nib:
override func awakeFromNib() {
super.awakeFromNib()
self.label.numberOfLines = 0
self.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
self.translatesAutoresizingMaskIntoConstraints = true
}