TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Unclaimed.
PinEntry is a small library that provides support for 4-digit pin code entries.
Custom UIView that implements look&feel of iOS numpad keyboard with support for additional buttion in lower left corner.
When positioning the view, best frame is CGRectMake(0, 244, 320, 216)
. That's the frame you get when using [[PENumpadView alloc] init];
Use the property detailButton to specify the look of the optional button.
@property (nonatomic, readwrite, assign) NSUInteger detailButon
To handle key presses you need to implement PENumpadViewDelegate
:
- (void)keyboardViewDidEnteredNumber:(int)num
Message is sent when digit key is tapped, num
contains the value in 0..9 range.
- (void)keyboardViewDidBackspaced
Message is sent when backspace is tapped.
- (void)keyboardViewDidOptKey
Message is sent when detailButon is something other than PEKeyboardDetailNone and the lower left button is tapped.
If you define PINENTRY_KEYBOARD_SENDS_NOTIFICATIONS, each tap would also generate kPinEntryKeyboardEvent notification, where object
is the PENumpadView, and detailInfo
contains the key kPinEntryKeyboardCode with NSNumber value. 0..9 correspond to digit keys, -1 – lower left button, -2 – backspace.
The view controller that implements pin entry. You can use it as modal controller or present in navigation stack.
You can set up the prompt using prompt property:
@property (nonatomic, readwrite, copy) NSString *prompt
The promt is displaed just above the pin boxes.
As soon as user enters 4 digits and taps "DONE", PEViewController sends pinEntryControllerDidEnteredPin:
message to its delegate
:
- (void)pinEntryControllerDidEnteredPin:(PEViewController *)controller
You can then get access to pin
property that holds string representation of the pin code. Here's a sample implementation of pin processing:
- (void)pinEntryControllerDidEnteredPin:(PEViewController *)controller
{
if([controller.pin intValue] == 1234) {
// ...
}
}
You can use resetPin
method to clear the current pin code, to make your PEViewController instance re-usable.
A complete implementation of navigation stack, required to ask user for a pin code, update a pin code or create new pin code.
- (void)verifyPin
{
PEPinEntryController *c = [PEPinEntryController pinVerifyController];
c.pinDelegate = self;
[self presentModalViewController:c animated:YES];
}
- (BOOL)pinEntryController:(PEPinEntryController *)c shouldAcceptPin:(NSUInteger)pin
{
// Verify the pin, return NO if it's incorrect. Otherwise hide the controller and return YES
if(pin == mypin) {
NSLog(@"Pin is valid!");
return YES;
} else {
NSLog(@"Pin is not valid (use %d)!", mypin);
return NO;
}
}
- (void)setPin
{
PEPinEntryController *c = [PEPinEntryController pinCreateController];
c.pinDelegate = self;
[self presentModalViewController:c animated:YES];
}
- (void)pinEntryController:(PEPinEntryController *)c changedPin:(NSUInteger)pin
{
// Update your info to new pin code
NSLog(@"New pin is set to %d", pin);
[self dismissModalViewControllerAnimated:YES];
}
- (void)chagePin
{
PEPinEntryController *c = [PEPinEntryController pinChangeController];
c.pinDelegate = self;
[self presentModalViewController:c animated:YES];
}
- (BOOL)pinEntryController:(PEPinEntryController *)c shouldAcceptPin:(NSUInteger)pin
{
// Verify the pin, return NO if it's incorrect
if(pin == mypin) {
NSLog(@"Pin is valid!");
// Do NOT not hide pinChangeController yet
return YES;
} else {
NSLog(@"Pin is not valid (use %d)!", mypin);
return NO;
}
}
- (void)pinEntryController:(PEPinEntryController *)c changedPin:(NSUInteger)pin
{
// Update your info to new pin code
NSLog(@"New pin is set to %d", pin);
[self dismissModalViewControllerAnimated:YES];
}
- (void)pinEntryControllerDidCancel:(PEPinEntryController *)c
{
NSLog(@"Pin change cancelled!");
[self dismissModalViewControllerAnimated:YES];
}