|
| 1 | +UIPasscodeViewController |
| 2 | +======================== |
| 3 | + |
| 4 | +Want a Passcode view for your iPhone/iPod project ? |
| 5 | +Here's how to add a UIPasscodeViewController on your project with a few lines of code. |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +How to use |
| 13 | +---------- |
| 14 | + |
| 15 | +1. Copy UIPasscodeViewController.m and UIPasscodeViewController.h files to your source tree and add it to XCode project. |
| 16 | +2. Import "UIPasscodeViewController.h" from your code. |
| 17 | +3. Implement UIPasscodeViewControllerDelegate protocol. |
| 18 | + |
| 19 | + |
| 20 | +Just #import the UIPasscodeViewController.h header |
| 21 | + |
| 22 | +`#import "UIPasscodeViewController.h"` |
| 23 | + |
| 24 | + |
| 25 | +Simple example of how to create UIPasscodeViewController: |
| 26 | + |
| 27 | +` |
| 28 | + UIPasscodeViewController *passcodeViewController = [[UIPasscodeViewController alloc] initWithDelegate:self]; |
| 29 | + |
| 30 | + UINavigationController *navController = [[UINavigationController alloc] |
| 31 | + initWithRootViewController:passcodeViewController]; |
| 32 | + |
| 33 | + [self setNavigationController:navController]; |
| 34 | + |
| 35 | + [window addSubview:[navController view]]; |
| 36 | + [window makeKeyAndVisible]; |
| 37 | + |
| 38 | + [window release]; |
| 39 | + [navController release]; |
| 40 | +` |
| 41 | + |
| 42 | +Your class will have to implement the UIPasscodeViewControllerDelegate protocol, and to implement the `didShowPasscodePanel:panelView:`, `shouldChangePasscode:panelView:passCode:lastNumber:` and `didEndPasscodeEditing:panelView:passCode:` methods from this protocol: |
| 43 | + |
| 44 | +` |
| 45 | +- (void) didShowPasscodePanel:(UIPasscodeViewController *)passcodeView panelView:(UIView*)panelView |
| 46 | +{ |
| 47 | + [passcodeView setTitle:@"Set Passcode"]; |
| 48 | + |
| 49 | + if([panelView tag] == kPasscodePanelOne) { |
| 50 | + [[passcodeView titleLabel] setText:@"Enter a passcode"]; |
| 51 | + } |
| 52 | + |
| 53 | + if([panelView tag] == kPasscodePanelTwo) { |
| 54 | + [[passcodeView titleLabel] setText:@"Re-enter your passcode"]; |
| 55 | + } |
| 56 | + |
| 57 | + if([panelView tag] == kPasscodePanelThree) { |
| 58 | + [[passcodeView titleLabel] setText:@"Panel 3"]; |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +- (BOOL)shouldChangePasscode:(UIPasscodeViewController *)passcodeView panelView:(UIView*)panelView passCode:(NSUInteger)passCode lastNumber:(NSInteger)lastNumber; |
| 63 | +{ |
| 64 | + // Clear summary text |
| 65 | + [[passcodeView summaryLabel] setText:@""]; |
| 66 | + |
| 67 | + return TRUE; |
| 68 | +} |
| 69 | + |
| 70 | +- (BOOL)didEndPasscodeEditing:(UIPasscodeViewController *)passcodeView panelView:(UIView*)panelView passCode:(NSUInteger)passCode |
| 71 | +{ |
| 72 | + |
| 73 | + NSLog(@"END PASSCODE - %d", passCode); |
| 74 | + |
| 75 | + if([panelView tag] == kPasscodePanelOne) { |
| 76 | + _passCode = passCode; |
| 77 | + |
| 78 | + return ![passcodeView nextPanel]; |
| 79 | + } |
| 80 | + |
| 81 | + if([panelView tag] == kPasscodePanelTwo) { |
| 82 | + _retryPassCode = passCode; |
| 83 | + |
| 84 | + if(_retryPassCode != _passCode) { |
| 85 | + [passcodeView prevPanel]; |
| 86 | + [[passcodeView summaryLabel] setText:@"Passcode did not match. Try again."]; |
| 87 | + return FALSE; |
| 88 | + } else { |
| 89 | + [[passcodeView summaryLabel] setText:@"Good boy !"]; |
| 90 | + } |
| 91 | + |
| 92 | + } |
| 93 | + |
| 94 | + return TRUE; |
| 95 | +} |
| 96 | +` |
| 97 | + |
| 98 | +Class References |
| 99 | +---------------- |
| 100 | + |
| 101 | +### UIPasscodeViewController |
| 102 | + |
| 103 | +#### initWithDelegate |
| 104 | + |
| 105 | +`-(id)initWithDelegate:(id)delegate` |
| 106 | + |
| 107 | +Initializes a UIPasscodeView. |
| 108 | + |
| 109 | +#### titleLabel |
| 110 | + |
| 111 | +`UILabel *titleLabel` |
| 112 | + |
| 113 | +The label used for the Passcode title. |
| 114 | + |
| 115 | +#### summaryLabel |
| 116 | + |
| 117 | +`UILabel *summaryLabel` |
| 118 | + |
| 119 | +The label used to show a summary text of the Passcode. |
| 120 | + |
| 121 | +#### clearPanel |
| 122 | + |
| 123 | +`- (void)clearPanel` |
| 124 | + |
| 125 | +Reset current panel passcode view. |
| 126 | + |
| 127 | +#### prevPanel |
| 128 | + |
| 129 | +`-(BOOL)prevPanel` |
| 130 | + |
| 131 | +Switch to the previous passcode panel. |
| 132 | + |
| 133 | +#### nextPanel |
| 134 | + |
| 135 | +`-(BOOL)nextPanel` |
| 136 | + |
| 137 | +Switch to the next passcode panel. |
| 138 | + |
0 commit comments