I am encoding iOS 8+.
I have a UICollectionReusableView that is used as a UICollectionView header
class UserHeader: UICollectionReusableView { ... }
The My View collection does a few things:
Loads NIB into viewDidLoad
override func viewDidLoad() { super.viewDidLoad() resultsCollectionView.registerNib(UINib(nibName: "UserHeader", bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "UserHeader") }
Sets the height of the header in referenceSizeForHeaderInSection .
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { return CGSizeMake(0, 500) }
However, my UserHeader consisted of a lot of UILabel, UIViews that change the height at runtime, how can I specify the height for referenceSizeForHeaderInSection this dynamic? Or, if I should not use referenceSizeForHeaderInSection for autosizing in iOS 8+, please let me know what I should use. Thanks in advance.
For completeness, here's how I download the view, but I'm not sure if this is relevant for this discussion:
func collectionView(collectionView: UICollectionView!, viewForSupplementaryElementOfKind kind: String!, atIndexPath indexPath: NSIndexPath!) -> UICollectionReusableView! { var reusableview:UICollectionReusableView = UICollectionReusableView() if (kind == UICollectionElementKindSectionHeader) { let userHeaderView = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier: "UserHeader", forIndexPath: indexPath) as! UserHeader ... extra code to modify UserHeader reusableview = userHeaderView } return reusableview }
ios swift uicollectionview
Dean
source share