2015-10-17 7 views
4

Привет, мне интересно, как мы можем достичь этого?UICollectionView Header and Footer View

в UITableView мы могли бы просто сделать tableView.tableHeaderView = SomeView; или tableView.tableFooterView = SomeView;

Но мне интересно, как сделать то же самое для UICollectionView.

PS: Не Раздел Колонтитулы

+2

Возможный дубликат [Пользовательский нижний колонтитул для UICollectionview в быстром режиме) (http://stackoverflow.com/questions/26892247/custom-footer-view-for-uicollectionview-in-swift) –

ответ

5

Попробуйте ...

Первый класс регистра в ViewDidLoad

registerClass(myFooterViewClass, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "Footer") 

затем использовать этот метод

override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { 

    switch kind { 

    case UICollectionElementKindSectionHeader: 

     let header = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "Header", forIndexPath: indexPath) as! UICollectionReusableView 

     header = SomeView 
     return header 

    case UICollectionElementKindSectionFooter: 
     let footer = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "Footer", forIndexPath: indexPath) as! UICollectionReusableView 

     footer= SomeView 
     return footer 

    default: 

     print("anything") 
    } 
} 

I надеюсь, что это поможет ...

+3

В этом вопросе говорится, что не заголовок раздела и Нижний колонтитул, и этот ответ о SectionHeader/Footer. –

1

UITableView имеют глобальные заголовки tableHeaderView и tableFooterView, но UICollectionView не имеет глобальных заголовков, поэтому вам придется использовать заголовки разделов.