Ich bin für iOS 8+ kodieren.UICollectionView AutoSize-Headerhöhe
Ich habe einen UICollectionReusableView
, die als Header UICollectionView
class UserHeader: UICollectionReusableView {
...
}
My View-Sammlung macht ein paar Dinge verwendet wird ist: in viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
resultsCollectionView.registerNib(UINib(nibName: "UserHeader", bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "UserHeader")
}
Sets Höhe Header in referenceSizeForHeaderInSection
Lasten NIB .
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSizeMake(0, 500)
}
jedoch meine UserHeader
Ansicht besteht aus vielen UILabel, UIViews wer Höhe zur Laufzeit verändert, wie kann ich eine Höhe für referenceSizeForHeaderInSection
angeben, die dynamisch ist? Oder wenn ich referenceSizeForHeaderInSection
nicht für die automatische Größenanpassung in iOS 8+ verwenden soll, lassen Sie mich bitte wissen, was ich verwenden soll. Danke im Voraus.
Der Vollständigkeit halber ist hier, wie ich die Ansicht laden, aber ich bin nicht sicher, ob das für diese Diskussion relevant ist:
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
}