TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Nov 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Andy Tong.
/// Create a AHBannerView
let bannerFrame = CGRect(x: 0, y: 64.0, width: self.view.bounds.width, height: 200.0)
bannerView = AHBannerView(frame: bannerFrame)
/// Create a style
var style = AHBannerStyle()
/// NOTE: This placeholder only appears when you haven't assigned a image for a imageView passed in the delegate method.
style.placeholder = UIImage(named: "placeholder")
style.isAutoSlide = true
// style.isInfinite = false
// style.isPagingEnabled = false
style.timeInterval = 1
/// Assigning delegate and add the bannerView to a view
bannerView.delegate = self
self.view.addSubview(bannerView)
style.bottomHeight = 5.0
style.showIndicator = true
style.showPageControl = false
style.indicatorColor = UIColor.red
style.showPageControl = false
style.bottomHeight = 25.0
style.showIndicator = false
style.showPageControl = true
style.showIndicator = false
style.pageControlColor = UIColor.gray
style.pageControlSelectedColor = UIColor.red
/// NOTE: The this/that URL guard statement in the following, is for preventing images being mismatched and assigned to the wrong imageView, when the inital imageView being recyled before the initial image request callback gets called. It's the same idea applied when you deal with tableView/collectionView cells.
func bannerViewForImage(_ bannerView: AHBannerView, imageView: UIImageView, atIndex: Int) {
let thisURL = URL(string: self.images[atIndex])
imageView.contentMode = .scaleAspectFill
imageView.sd_setImage(with: thisURL) {[weak self] (image, _, _, thatURL) in
guard self != self else {return}
/// See the note above
guard thisURL == thatURL else {return}
guard let image = image else {return}
imageView.image = image
}
}
To run the example project, clone the repo, and run pod install
from the Example directory first.
AHBannerView is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod "AHBannerView"
Andy Tong, [email protected]
AHBannerView is available under the MIT license. See the LICENSE file for more info.