RCPageControl
又一个 iOS 上的页面控件,用 Facebook pop 库提供出色的动画。
有什么想法让这个控件更出色吗?请随时提出问题或提交 PR。
要求
- Xcode 10.0 或更高版本
- iOS 8.0 或更高版本
- ARC
- pop 动画库
运行示例
在您的终端中,
cd [workspace]/RCPageControl/RCPageControlExample
pod install
然后,
open RCPageControlExample.xcworkspace
或者输入 xed .
。
安装
安装 RCPageControl
的推荐方法是使用 CocoaPods 包管理器。
在您的 Podfile
中添加以下行
pod 'RCPageControl'
然后,
pod update
使用方法
RCPageControl
的API高度类似于UIPageControl
。
1. 首先
通过包含以下导入使用
Objective-C
#import <RCPageControl/RCPageControl.h>
或者如果您在使用内置框架
@import RCPageControl;
Swift
import RCPageControl
2. 初始化
initWithFrame:
使用Objective-C
RCPageControl *pageControl = [RCPageControl initWithFrame:CGRectMake(0, 0, 100, 10)];
Swift
let pageControl = RCPageControl(frame: CGRect(x: 0, y: 0, width: 100, height: 10))
initWithNumberOfPages:
使用 Objective-C
RCPageControl *pageControl = [RCPageControl initWithNumberOfPages:5];
Swift
let pageControl = RCPageControl(numberOfPages: 5)
3. 回调
UIControlEvent
使用 Objective-C
[pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];
Swift
pageControl?.addTarget(self, action: #selector(changePage(sender:)), for: .valueChanged)
RCCurrentPageChangedBlock
使用 Objective-C
[pageControl setCurrentPageChangedBlock:^(RCPageControl *pageControl) {
// Code here
}];
Swift
pageControl?.currentPageChangedBlock = { (pageControl) in
// Code here
}
4. 属性
仅列出 RCPageControl
的新属性。
-
indicatorDotGap 从点边缘到点边缘的距离。默认值为
10.0
,不能小于2.0
。 -
indicatorDotWidth 点的宽度,你可以假设点是圆形的。默认值为
4.0
,不能小于2.0
。 -
animationSpeed & animationBounciness
我们使用 POPSpringAnimation
为点进行动画。更多信息请参阅 POPSpringAnimation.h。
- 动画持续时间
UIView animation
的持续时间。用于 _indicatorIndexLabel
的动画。只有当 hideCurrentPageIndex
设置为 NO
时才可用。默认是 0.6
。
- 动画缩放因子
点缩放因子。用于计算当前点的宽度。默认值为 2
。
- hideCurrentPageIndex
当设置为 YES
时,将隐藏 Page Index Label
。默认为 NO
。显示的页面从 1
开始。
- disableAnimation
当设置为 YES
时,将禁用所有指示点变化动画。默认为 NO
。
- pageIndicatorTintColor
点的背景颜色。默认为 [UIColor lightTextColor]
。
- currentPageIndicatorTintColor
当前点的背景颜色。默认为 [UIColor whiteColor]
。
- currentPageIndexTextTintColor
Page Index Label
的 TextColor
。默认为 [UIColor darkTextColor]
。
- currentPageIndexTextFont
《页面索引标签》的《字体》。默认为《UIFont systemFontOfSize:0》。字体大小将自动根据《indicatorDotWidth》和《animationScaleFactor》的值调整。
许可协议
RCPageControl遵循MIT许可协议。更多信息请参阅LICENSE文件。