AHBannerView 0.3.2

AHBannerView 0.3.2

测试教程
语言语言 SwiftSwift
许可证 MIT
发布最后发布2017年11月
SwiftSwift版本3.0
SPM支持SPM

Andy Tong维护。



  • 作者:
  • Andy Tong

AHBannerView

1. 在底部显示条形指示器

2. 在底部显示分页控制

使用方法

步骤

  1. 使用一个frame和一个AHBannerStyle创建AHBannerView实例。
  2. 使用一个imageCount和你刚刚创建的AHBannerStyle设置AHBannerView
  3. 将AHBannerView添加到一个视图
  4. 指定并实现代理。

示例代码

1. 基本代码

/// 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)

2.1 风格A:显示条形指示器

style.bottomHeight = 5.0

style.showIndicator = true
style.showPageControl = false
style.indicatorColor = UIColor.red
        
style.showPageControl = false

2.2 风格B:显示分页控件

style.bottomHeight = 25.0

style.showIndicator = false

style.showPageControl = true
style.showIndicator = false
style.pageControlColor = UIColor.gray
style.pageControlSelectedColor = UIColor.red

3. 实现代理来告诉AHBannerView每个横幅显示什么

/// 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文件。