How can I add loading Indicator in the Footer of collection view when data is loaded for next page..?
I want to loading indicator in Footer of Collection vi
The simplest solution would be adding the activity indicator to a view and add that view to UICollectionReusableView.
In collection view :
private let footerView = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.white)
override func viewDidLoad() {
super.viewDidLoad()
collectionView.register(CollectionViewFooterView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "Footer")
(collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.footerReferenceSize = CGSize(width: collectionView.bounds.width, height: 50)
}
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if kind == UICollectionView.elementKindSectionFooter {
let footer = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Footer", for: indexPath)
footer.addSubview(footerView)
footerView.frame = CGRect(x: 0, y: 0, width: collectionView.bounds.width, height: 50)
return footer
}
return UICollectionReusableView()
}
customized class: add your customizations here if you need any
public class CollectionViewFooterView: UICollectionReusableView {
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
just use: footerView.startAnimating() & footerView.stopAnimating() for start or stop the animation
***** Hope you like it .******