Skip to content

This is an infinite scroll view implemented with uicollectionview, which can be used as banner, pagerview, padding and item spacing can be defined.

License

Notifications You must be signed in to change notification settings

chinghoi/CHPagerView

Repository files navigation

CHPagerView

Version License Platform

更新日志

v1.0.4: 手指滑动效果增加连续或者不连续

说明

为什么要重复造一个轮子?因为有时候只是想开箱即用一个轮播图或者左右滑动的视图,却要写一堆代理,所以写了能简单用一下的库, 可以直接设置数据。 库很轻量,仅有的 AlamofireImage 在1.0版本中也被去除,如使用有什么疑问,欢迎提 Issues。

支持设备

  • iOS 10.0 or later.
  • swift 5 or later.

支持

  • 可设置banner内边距 Content edges.
  • 设置 图片, 自定义视图或者网络图片链接 Set images, custom views or urls.
  • 滚动方向 Scroll direction: vertical or horizontal.
  • 各项间距设置 Item spacing.
  • 自动滚动,无限或者有限滚动 Can set auto rotation, Is it an infinite loop.
  • 如果设置 urls,会缓存加载完成的图片。
  • 多长时间滚动一次

安装

CHPagerView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'CHPagerView'

然后在项目目录运行pod install

使用方法

基本用法(传入图片)

let bannerView = CHPagerView()
let images = [UIImage(named: "1")!, UIImage(named: "2")!, UIImage(named: "3")!]
bannerView.setData(images)

或者(传入自定义视图)

let customViews: [UIView] = [UIColor.red, UIColor.yellow, UIColor.green].map {
    let v = UIView()
    v.backgroundColor = $0
    return v
    } 
bannerView.setData(customViews)

或者(传入网络图片地址)

let urls = ["https://github.com/chinghoi/CHPagerView/blob/master/png1.png?raw=true",
            "https://github.com/chinghoi/CHPagerView/blob/master/png2.png?raw=true"]
bannerView.setData(urls, placeholder: UIImage(named: "placeholder"))

代理

lazy var bannerViewTwo: CHPagerView = {
    let b = CHPagerView()
    b.delegate = self
    return b
}()

...

func pagerView(_ pagerView: CHPagerView, didSelectItemAt index: Int)
func pagerViewDidEndScroll(_ pagerView: CHPagerView, current index: Int)

更多使用方法见 demo。

依赖

- AlamofireImage 4.1+(已移除)

Author

Chinghoi, 56465334@qq.com

License

CHPagerView is available under the MIT license. See the LICENSE file for more info.

About

This is an infinite scroll view implemented with uicollectionview, which can be used as banner, pagerview, padding and item spacing can be defined.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published