CFSecurityCodeButton 是一个简约的验证码按钮。
- 自定义 Normal 状态下文字和 Disabled 状态下文字
- 自动根据N ormal 和 Disabled 状态下文字设置宽高
- 自定义定时时间
- 自动根据按钮的主题色调整文字颜色
- 提供了代理方法监控按钮开始计时和计时结束
- 提供了一些好看的颜色供使用者选择
-
手动安装 将
CFSecurityCodeButton.h
、CFSecurityCodeButton.m
拖入你的项目中 -
CocoaPods
pod ‘CFSecurityCodeButton’
-
创建 通过主题色创建一个 CFSecurityCodeButton
CFSecurityCodeButton *btSecurityCode_Blue = [[CFSecurityCodeButton alloc] initWithColor:CFColorDodgerBlue];
提供了一些颜色供使用者选择
CFColorCoral CFColorDodgerBlue CFColorDeepSkyBlue CFColorTurquoise CFColorWarmYellow CFColorMediumPurple CFColorSeaGreen
-
设置文字 如果没有设置,默认 Normal 状态会显示"发送验证码",Disabled 状态会显示"再次发送(倒计时)" 如果需要自定义可以设置
normalTitle
和disabledTitle
属性btSecurityCode.normalTitle = @"自定义normal状态文字内容"; btSecurityCode.disabledTitle = @"自定义disabled状态文字内容";
-
设置倒计时 如果没有设置,默认倒计时为 60 秒 如果需要自定义可以设置
time
属性btSecurityCode.time = 60;
-
自动调节文字颜色 CFSecurityCodeButton 会根据自身的颜色调节文字颜色,当颜色过深时文字将会变成白色,当颜色过浅时文字颜色将会变成黑色
-
代理 提供了两个代理方法监控按钮
/** * 按钮被点击 * * @param securityCodeButton CFSecurityCodeButton对象 */ - (void)securityCodeButtonDidClicked:(CFSecurityCodeButton *)securityCodeButton; /** * 按钮倒计时结束 * * @param securityCodeButton CFSecurityCodeButton对象 */ - (void)securityCodeButtonTimingEnded:(CFSecurityCodeButton *)securityCodeButton;
只需要实现
CFSecurityCodeButtonDelegate
,重写代理方法 -
为了避免内存泄露:
/** invalidate NSTimer */ - (void)stopTiming;
如果有什么修改建议,可以发送邮件到 coderfish@163.com,也欢迎到我的博客