Passcode view controller for iPhone/iPod.
Objective-C
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
PTPasscodeViewControllerDemo
README.mdown

README.mdown

PTPasscodeViewController

Want a Passcode view for your iPhone/iPod project ? Here's how to add a PTPasscodeViewController on your project with a few lines of code.

How to use

  1. Copy PTPasscodeViewController.m and PTPasscodeViewController.h files to your source tree and add it to XCode project.
  2. Import "PTPasscodeViewController.h" from your code.
  3. Implement PTPasscodeViewControllerDelegate protocol.

Just #import the PTPasscodeViewController.h header

#import "PTPasscodeViewController.h"

Simple example of how to create PTPasscodeViewController:

PTPasscodeViewController *passcodeViewController = [[PTPasscodeViewController alloc] initWithDelegate:self];

UINavigationController *navController = [[UINavigationController alloc]
                             initWithRootViewController:passcodeViewController];

[self setNavigationController:navController];

[window addSubview:[navController view]];
[window makeKeyAndVisible];

[window release];
[navController release];

Your class will have to implement the PTPasscodeViewControllerDelegate protocol, and to implement the didShowPasscodePanel:panelView:, shouldChangePasscode:panelView:passCode:lastNumber: and didEndPasscodeEditing:panelView:passCode: methods from this protocol:

- (void)didShowPasscodePanel:(PTPasscodeViewController *)passcodeViewController panelView:(UIView*)panelView
{
    [passcodeViewController setTitle:@"Set Passcode"];
    
    if([panelView tag] == kPasscodePanelOne) {
       [[passcodeViewController titleLabel] setText:@"Enter a passcode"];
    }

    if([panelView tag] == kPasscodePanelTwo) {
        [[passcodeViewController titleLabel] setText:@"Re-enter your passcode"];
    }

    if([panelView tag] == kPasscodePanelThree) {
        [[passcodeViewController titleLabel] setText:@"Panel 3"];
    }
}

- (BOOL)shouldChangePasscode:(PTPasscodeViewController *)passcodeViewController panelView:(UIView*)panelView passCode:(NSUInteger)passCode lastNumber:(NSInteger)lastNumber;
{
    // Clear summary text
    [[passcodeViewController summaryLabel] setText:@""];

    return TRUE;
}

- (BOOL)didEndPasscodeEditing:(PTPasscodeViewController *)passcodeViewController panelView:(UIView*)panelView passCode:(NSUInteger)passCode
{
    
    NSLog(@"END PASSCODE - %d", passCode);
    
    if([panelView tag] == kPasscodePanelOne) {
        _passCode = passCode;
        
        return ![passcodeViewController nextPanel];
    }

    if([panelView tag] == kPasscodePanelTwo) {
        _retryPassCode = passCode;
        
        if(_retryPassCode != _passCode) {
            [passcodeViewController prevPanel];
            [[passcodeViewController summaryLabel] setText:@"Passcode did not match. Try again."];
            return FALSE;
        } else {
            [[passcodeViewController summaryLabel] setText:@"Good boy !"];    
        }
        
    }
    
    return TRUE;
}

Class References

PTPasscodeViewController

initWithDelegate

-(id)initWithDelegate:(id)delegate

Initializes a PTPasscodeViewController.

titleLabel

UILabel *titleLabel

The label used for the Passcode title.

summaryLabel

UILabel *summaryLabel

The label used to show a summary text of the Passcode.

clearPanel

- (void)clearPanel

Reset current panel passcode view.

prevPanel

-(BOOL)prevPanel

Switch to the previous passcode panel.

nextPanel

-(BOOL)nextPanel

Switch to the next passcode panel.

License

(The MIT License)

Copyright (c) 2012 Picktek LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.