How do I add a UIActivityIndicatorView
to footer of UICollectionView
in swift? For UITableView
, it was just self.tableView.tableFootView = self.myActivityIndicatorView
. Is this possible? If so, how?
In Attribute inspector with your Collection View selected check the Section Footer in Accessories . So, It will add footerview in your collection view and you can easily drag and drop activity indicator to this footerView .
Select the Collection Reusable View of the header, set the identifier as “HeaderView” in the Attributes inspector. For the Collection Reusable View of the footer, set the identifier as “FooterView”.
collectionView(_:viewForSupplementaryElementOfKind:at:)Asks your data source object to provide a supplementary view to display in the collection view.
Create view class and add activity indication in that view
Register this class as footer view class using:
registerClass(myFooterViewClass, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "myFooterView")
Either set the headerReferenceSize on your collection view layout or implement
collectionView:layout:referenceSizeForHeaderInSection: in your delegate.
Return the footer view from the following method in your dataSource:
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
let view = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionFooter, withReuseIdentifier: "myFooterView", forIndexPath: indexPath)
// configure footer view
return view
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With