मैं आईओएस 8+ के लिए कोडिंग कर रहा हूं। viewDidLoad
UICollectionView ऑटोसाइज हेडर ऊंचाई
override func viewDidLoad() {
super.viewDidLoad()
resultsCollectionView.registerNib(UINib(nibName: "UserHeader", bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "UserHeader")
}
सेट में
भार निब referenceSizeForHeaderInSection
में ऊंचाई शीर्षक:
मैं एक UICollectionReusableView
कि UICollectionView
class UserHeader: UICollectionReusableView {
...
}
मेरे देखें संग्रह हेडर के रूप में इस्तेमाल किया जा रहा करता है कुछ चीजें है ।
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSizeMake(0, 500)
}
लेकिन, मेरा UserHeader
दृश्य कई UILabel, UIViews के शामिल है जो ऊंचाई रन टाइम पर बदल जाता है, मैं कैसे referenceSizeForHeaderInSection
कि गतिशील है के लिए एक ऊंचाई निर्दिष्ट कर सकते हैं क्या है? या यदि मुझे आईओएस 8+ में ऑटो-साइजिंग के लिए referenceSizeForHeaderInSection
का उपयोग नहीं करना है, तो कृपया मुझे बताएं कि मुझे क्या उपयोग करना चाहिए। अग्रिम में धन्यवाद।
पूर्णता के लिए, यहाँ मैं कैसे दृश्य लोड है, लेकिन मुझे यकीन है कि अगर यह चर्चा के लिए प्रासंगिक है नहीं कर रहा हूँ:
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
}