Tôi đang mã hóa cho iOS 8+.UICollectionView Chiều cao tiêu đề AutoSize
Tôi có một UICollectionReusableView
đó được sử dụng như là tiêu đề của UICollectionView
class UserHeader: UICollectionReusableView {
...
}
Xem Bộ sưu tập của tôi làm một vài điều:
tải NIB trong viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
resultsCollectionView.registerNib(UINib(nibName: "UserHeader", bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "UserHeader")
}
Sets tiêu đề chiều cao trong referenceSizeForHeaderInSection
.
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSizeMake(0, 500)
}
Tuy nhiên, UserHeader
quan điểm của tôi bao gồm nhiều UILabel, UIViews ai là chiều cao thay đổi tại thời gian chạy, làm thế nào tôi có thể chỉ định một chiều cao cho referenceSizeForHeaderInSection
đó là năng động? Hoặc nếu tôi không được phép sử dụng referenceSizeForHeaderInSection
để tự động định kích thước trong iOS 8+, vui lòng cho tôi biết những gì tôi nên sử dụng. Cảm ơn trước.
Đối với đầy đủ sake, dưới đây là cách tôi tải các quan điểm, nhưng tôi không chắc chắn nếu có liên quan để thảo luận này:
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
}