测试教程 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2017年11月 |
SwiftSwift版本 | 3.0 |
SPM支持SPM | ✗ |
由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
}
}
要运行示例项目,请克隆仓库,并在示例目录中首先运行pod install
。
通过CocoaPods安装AHBannerView。要安装它,只需将以下行添加到您的Podfile中
pod "AHBannerView"
Andy Tong, [email protected]
AHBannerView根据MIT许可证可用。有关更多信息,请参阅LICENSE文件。