LYPaymentSecurityField
目录Table of Contents
介绍 Introduction
LYPaymentSecurityField 是一个安全支付输入框,继承自系统的 UIControl。其实现原理相对简单,主要利用了系统的 UIKeyInput。它可以用于支付、安全登录以及需要安全验证等场景。LYPaymentSecurityField 提供了一些基本的方法及属性,例如:
/**
密码(字符)位数
*/
@property (nonatomic, assign) NSInteger numberOfCharacters;
/**
已经验证过的(输入满位的)次数
*/
@property (nonatomic, assign, readonly) NSInteger countOfVerification;
/**
输入满位时的回调
*/
@property (nonatomic, copy) void (^completion)(LYSecurityField *field, NSString *text);
/**
清空输入
*/
- (void)clear;
此外,LYPaymentSecurityField 还提供了一些已经与其他 UI 和安全输入框控件集成的控件,开发者可以直接使用。
LYPaymentSecurityField is a security payment entry box that inherits from the system's UIControl. Its implementation principle is relatively simple, mainly using the system's UIKeyInput. It can be used for payment, secure login, and other scenarios where security verification is required. LYPaymentSecurityField provides some basic methods and properties, such as
/**
Password (character) number of bits
*/
@property (nonatomic, assign) NSInteger numberOfCharacters;
/**
The number of times that have been verified (entered full)
*/
@property (nonatomic, assign, readonly) NSInteger countOfVerification;
/**
Enter the callback when the number of digits is full
*/
@property (nonatomic, copy) void (^completion)(LYSecurityField *field, NSString *text);
/**
Empty the characters that have been entered
*/
- (void)clear;
At the same time, LYPaymentSecurityField also provides some controls that have been integrated with other UI and security input box controls. Developers can directly use them.
截屏 Screenshots
动态演示 Dynamic presentation
模拟器效果不是太好,请到真机上运行^-^
安装方式 Installation
1. 手动拖入
下载demo,将demo中的PaymentField文件夹拖入到自己的工程中,在需要使用的页面,导入LYPaymentSecurityField.h #import "LYPaymentSecurityField.h"
2. Cocopods导入
Podfile里增加 pod 'LYPaymentField'
在需要使用到的页面 #import <LYPaymentSecurityField.h>
1. 手动
下载demo,演示 在PaymentField文件夹中将文件拖入自己的项目中,需要使用的页面,导入LYPaymentSecurityField.h #import "LYPaymentSecurityField.h"
2. Cocoapods
在Podfile中添加Pod 'LYPaymentField'
需要使用页面#import <LYPaymentSecurityField.h>
用法 Usage
// 基本用法
self.securityField = [[LYSecurityField alloc] initWithNumberOfCharacters:6 securityCharacterType:SecurityCharacterTypeSecurityDot borderType:BorderTypeHaveRoundedCorner];
self.securityField.frame = CGRectMake(15, 100, ScreenWidth-30, 50);
self.securityField.completion = ^(LYSecurityField * _Nonnull field, NSString * _Nonnull text) {
// 输入满格时被触发
// TO DO
};
[self.view addSubview:self.securityField];
// 明文Plaintext
self.securityField = [[LYSecurityField alloc] initWithNumberOfCharacters:6 securityCharacterType:SecurityCharacterTypePlainText borderType:BorderTypeHaveRoundedCorner];
self.securityField.frame = CGRectMake(15, 100, ScreenWidth-30, 50);
self.securityField.colorOfCharacter = UIColor.blueColor;//文字颜色
self.securityField.completion = ^(LYSecurityField * _Nonnull field, NSString * _Nonnull text) {
// 输入满格时被触发
// TO DO
};
[self.view addSubview:self.securityField];
// 短线加密符HorizontalLine
self.securityField = [[LYSecurityField alloc] initWithNumberOfCharacters:6 securityCharacterType:SecurityCharacterTypeHorizontalLine borderType:BorderTypeHaveRoundedCorner];
self.securityField.frame = CGRectMake(15, 100, ScreenWidth-30, 50);
// self.securityField.colorOfCharacter = UIColor.brownColor;//文字颜色
self.securityField.completion = ^(LYSecurityField * _Nonnull field, NSString * _Nonnull text) {
// 输入满格时被触发
// TO DO
};
[self.view addSubview:self.securityField];
// 自定义加密图片CustomImage
self.securityField = [[LYSecurityField alloc] initWithNumberOfCharacters:6 securityCharacterType:SecurityCharacterTypeCustomImage borderType:BorderTypeHaveRoundedCorner];
self.securityField.frame = CGRectMake(15, 100, ScreenWidth-30, 50);
self.securityField.securityImage = [UIImage imageNamed:@"mi"];
self.securityField.securityImageSize = CGSizeMake(32, 32);//图片默认尺寸25*25,可选
self.securityField.completion = ^(LYSecurityField * _Nonnull field, NSString * _Nonnull text) {
// 输入满格时被触发
// TO DO
};
[self.view addSubview:self.securityField];
为核心输入框组件LYSecurityField增加协议方法
/**
输入完成 end editing
@param paymentField 支付框
*/
- (void)lYPaymentFieldDidFinishedEditing:(LYSecurityField *)paymentField;
/**
开始输入 begin editing
@param paymentField 支付框
*/
- (void)lYPaymentFieldDidBeginEditing:(LYSecurityField *)paymentField;
/**
删除字符 delete a character
@param paymentField 支付框
*/
- (void)lYPaymentFieldDidDelete:(LYSecurityField *)paymentField;
/**
清除完成 clear all characters
@param paymentField 支付框
*/
- (void)lYPaymentFieldDidClear:(LYSecurityField *)paymentField;
为集成的支付弹框组件新增协议方法
@required
/**
支付密码输入完成
@param paymentController 弹窗
@param securityText 输入完成时的输入内容
*/
- (void)lYPaymentController:(LYPaymentAlertController *)paymentController securityTextOfCompeletion:(NSString *)securityText;
@optional
/**
正在输入密码
@param paymentController 支付弹框
@param securityText 输入的密码
*/
- (void)lYPaymentController:(LYPaymentAlertController *)paymentController didEditingSecurityText:(NSString *)securityText;
/**
清除完成
@param paymentController 支付弹框
*/
- (void)lYPaymentControllerDidClear:(LYPaymentAlertController *)paymentController;
属性 | 备注 |
---|---|
dotRadius | 加密黑点的半径 |
textColor | 前景色 |
characterColor | 加密图形的颜色 |
securityImage | 自定义加密图片 |
securityImageSize | 自定义加密图片的尺寸 |
verificationCount | readonly(输入满格)被校验的次数 |
--- | --- |