UIBannerView supports swift 5.0, iOS 12
- Add pod ‘UIBannerView’
- Install the pods by running pod install.
- Add import UIBannerView in the .swift files where you want to use it.
@IBOutlet weak var bannerView: UIBannerView!
self.bannerView.setDefaultBanners(banners: `yourArray`); // object of array has to conform IBannerModel protocol
create your custom cell.
private var yourArray = [YourArray]();
private func setUp()
{
self.bannerView.dataSource = self;
self.bannerView.delegate = self;
self.bannerView.addRegisterCustomCell(nibName: "CustomCell", forCellWithReuseIdentifier: "CustomCell");
self.bannerView.reloadData();
}
extension ViewController: UIBannerViewDataSource
{
func bannerView(_ bannerView: UIBannerView, didSelectItemAt indexPath: IndexPath)
{
print("tapped \(indexPath)");
}
}
extension ViewController: UIBannerViewDelegate
{
func bannerView(_ bannerView: UIBannerView, numberOfItemsInSection section: Int) -> Int
{
return self.customBanner.count;
}
func bannerView(_ bannerView: UIBannerView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = bannerView.dequeueReusableCell(withReuseIdentifier: "CustomCell", for: indexPath) as! CustomCell;
cell.bind(model: self.customBanner[indexPath.row]);
return cell;
}
}
cells width is equal to screens width - padding.
Item spacing is the gap between cell and the next one.
ShowPageControl: if off, it will not show, and if it's on, it will show (the page controler)
Left and right margins should be a total of 100 if the margin is more than 50, it will show more than needed.
If the PagingEnabled is on, it will treat the screens as pages, and if its off it will show them as free scroll
Track color is related to show page control, it will mark the active page on the page scroll
UIBannerView uses SDWebImage