AdvancedPageControl
一个用于iOS的简单而强大的页面控制指示器动画库,用Swift编写。
示例
要运行示例项目,请克隆仓库,并首先从示例目录运行pod install
。
安装
AdvancedPageControl可以通过CocoaPods获取。要安装它,只需将以下行添加到Podfile
pod 'AdvancedPageControl'
效果
- 颜色混合
- 滴落
- 扩展点
- 跳跃
- 缩放
- 滑动
- 交换
- 蠕虫
- 细蠕虫
- 细蠕虫头部
- 滚动
- 无限
使用方法
我使用它与扩展的UICollectionView结合,创建一个收藏夹视图,将数据源和代理链接到您的ViewController,并添加UICollectionViewDeleageFlowLayout
class ViewController: UIViewController,
UICollectionViewDataSource,
UICollectionViewDelegate,
UICollectionViewDelegateFlowLayout { ....
然后添加以下方法
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 5
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
return collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
}
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: collectionView.frame.width, height: 250) // This is to restric the item width and heigth to achive the single item preview
}
在Storyboard中,在UICollectionView属性中标记'启用滚动'和'启用分页'复选框
然后添加此方法,并将UICollectionView的滚动偏移和宽度传递给pageControl的setCurrentItem方法
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offSet = scrollView.contentOffset.x
let width = scrollView.frame.width
pageControl.setPageOffset(offSet/width)
// OR
let index = Int(round(offSet/width))
pageControl.setPage(index) // This will animate the page controll transition, whenever the index is changed, no need to pass an offset of every scroll offset
}
然后设置任何您喜欢的drawer在viewDidLoad方法中
pageControl1.drawer = ColorBlendDrawer()
或者您可以选择以下任一选项
ColorBlendDrawer()
DropDrawer()
ExtendedDotDrawer()
JumpDrawer()
ScaleDrawer()
SlideDrawer()
SwapDrawer()
ThinWormDrawer()
ThinWormHeadsDrawer()
WormDrawer()
Scrolling()
Infinite()
自定义
ScaleDrawer(numberOfPages:Int? = 5,
height: CGFloat? = 16,
width: CGFloat? = 16,
space: CGFloat? = 16,
radius: CGFloat? = 16,
currentItem: CGFloat? = 0,
indicatorColor: UIColor? = .red,
dotsColor: UIColor? = .lightGray)
作者
Mohanned Binmiskeen, [email protected]
许可证
AdvancedPageControl在MIT许可证下可用。有关更多信息,请参阅LICENSE文件。