项目作者: benjamin-wen

项目描述 :
Local CAPTCHA View Demo
高级语言: Objective-C
项目地址: git://github.com/benjamin-wen/CaptchaView.git
创建时间: 2015-11-27T07:08:26Z
项目社区:https://github.com/benjamin-wen/CaptchaView

开源协议:MIT License

下载


VFCaptchaView v1.0.0 []
本地授权码验证View

996.icu

一个本地的授权码验证View

Captcha View generated locally.

Usage

Initialize

success is the callback on success in which case analyser returns YES.
On the other hand, block failure is called on failure and analyser returns NO.
Analyser is the verificator. It allows you to controller the logic (eg. equation, case-sensitiveness).

failure 验证失败的回调,即 analyser 返回 YES 的时候;
success 验证成功的回调,即 analyser 返回 YES 的时候;
analyser 你可以通过这个 block 控制验证的逻辑(如相等,忽略大小写等)。

  1. self.captchaView = [[VFCaptchaView alloc] initWithFrame:CGRectMake(20.f, 40.f, SCREEN_WIDTH - 40.f, 40) success:^(NSString *verificationCode) {
  2. NSString *title = @"Verification Succeeded!";
  3. NSString *message = @"🤗";
  4. NSString *cancelButtonTitle = @"Yeah";
  5. // do things on verification success
  6. if ([[UIDevice currentDevice].systemVersion floatValue] < 9.0) {
  7. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil, nil];
  8. [alertView show];
  9. } else {
  10. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  11. [alertController addAction:[UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:nil]];
  12. [self presentViewController:alertController animated:YES completion:nil];
  13. }
  14. } failure:^{
  15. // do things on verification failure
  16. NSString *title = @"Verification Failed!";
  17. NSString *message = @"😂";
  18. NSString *cancelButtonTitle = @"Try Again";
  19. // do things on verification success
  20. if ([[UIDevice currentDevice].systemVersion floatValue] < 9.0) {
  21. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil, nil];
  22. [alertView show];
  23. } else {
  24. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  25. [alertController addAction:[UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:nil]];
  26. [self presentViewController:alertController animated:YES completion:nil];
  27. }
  28. } withAnalyser:^BOOL(NSString *verificationCode) {
  29. return [verificationCode isEqualToString:self.textField.text];
  30. }];

Set Verfification Code

  1. [self.captchaView setCaptchaCode:@"自定义文字abc123ABC"];

Add Captcha as subview

  1. [self.view addSubview:self.captchaView];

Screenshots

Verification succeed :)

Verification failed :(