ResetLockViewController.h/ResetLockViewControll...

ResetLockViewController.h

//
//  ResetLockViewController.h
//  ProtectedData
//
//  Created by  on 7/6/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "LockView.h"

@interface  ResetLockViewController : UIViewController <LockViewDelegate>

//  在屏幕上方显示字符串
@property (nonatomic, strong) UILabel *setAppLockLabel;

@property (nonatomic, strong) LockView *lockView;

//  在屏幕下方显示两个按钮
@property (nonatomic, strong) UIButton *resetButton;
@property (nonatomic, strong) UIButton *useButton;

@end  

ResetLockViewController.m

//
//  ResetLockViewController.m
//  ProtectedData
//
//  Created by  on 7/6/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ResetLockViewController.h"
#import "AppDefine.h"
#import "NSString+MD5HexDigest.h"
#import "LoginViewController.h"

@interface  ResetLockViewController ()

- (UIButton *)newButtonWithTitle:(NSString *)title target:(id)target selector:(SEL)selector frame:(CGRect)frame image:(UIImage *)image imagePressed:(UIImage *)imagePressed darkTextColor:(BOOL)darkTextColor;

- (void)resetButtonTapped:(id)sender;
- (void)useButtonTapped:(id)sender;

@end 

@implementation ResetLockViewController

@synthesize setAppLockLabel;
@synthesize lockView;
@synthesize resetButton;
@synthesize useButton;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - catorgery
- (UIButton *)newButtonWithTitle:(NSString *)title target:(id)target selector:(SEL)selector frame:(CGRect)frame image:(UIImage *)image imagePressed:(UIImage *)imagePressed darkTextColor:(BOOL)darkTextColor
{
    UIButton *button = [[UIButton alloc] initWithFrame:frame];
    
    button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    
    [button setTitle:title forState:UIControlStateNormal];
    if (darkTextColor) {
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    } else {
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    
    UIImage *newImage = [image stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
    [button setBackgroundImage:newImage forState:UIControlStateNormal];
    
    UIImage *newPressedImage = [imagePressed stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
    [button setBackgroundImage:newPressedImage forState:UIControlStateHighlighted];
    
    [button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    
    button.backgroundColor = [UIColor clearColor];
    
    return button;
}

- (void)resetButtonTapped:(id)sender
{
    [self.lockView resetButtons];
}

- (void)useButtonTapped:(id)sender
{
    NSLog(@"%@", self.lockView.lastSelectedButtonsIndexArray);
    
    NSMutableString *unlockKey = [NSMutableString string];
    for (NSNumber *index in self.lockView.lastSelectedButtonsIndexArray) {
        [unlockKey appendFormat:@"%i", index.integerValue];
    }
    
    NSString *unlockKeyWithMd5 = [NSString stringWithString:[unlockKey md5HexDigest]];
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:unlockKeyWithMd5 forKey:USERDEFAULTAPPLOCKKEY];
    [userDefaults setBool:YES forKey:USERDEFAULTISAPPLOCKKEYSETTED];
    
    LoginViewController *loginViewController = [[LoginViewController alloc] init];
    [self.navigationController pushViewController:loginViewController animated:YES];
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
    
}
*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [self.navigationController setNavigationBarHidden:YES];
    
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    
    self.lockView = [LockView instanceWithFrame:self.view.bounds WithDelegate:self];
    [self.view addSubview:self.lockView];
    
    self.setAppLockLabel = [[UILabel alloc] initWithFrame:CGRectMake(20.0f, 20.0f, self.view.bounds.size.width - 40.0f, 46.0f)];
    self.setAppLockLabel.backgroundColor = [UIColor clearColor];
    self.setAppLockLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [self.setAppLockLabel setTextAlignment:UITextAlignmentCenter];
    [self.setAppLockLabel setTextColor:[UIColor whiteColor]];
    [self.setAppLockLabel setFont:[UIFont boldSystemFontOfSize:30.0f]];
    self.setAppLockLabel.text = NSLocalizedString(@"SetAppLockLabelText", nil);
    [self.view addSubview:self.setAppLockLabel];
    
    UIImage *blueImage = [UIImage imageNamed:@"blueButton.png"];
    UIImage *whiteImage = [UIImage imageNamed:@"whiteButton.png"];
    UIImage *redImage = [UIImage imageNamed:@"redButton.png"];
    
    CGRect resetButtonFrame = CGRectMake(30.0f, 390.0f, 115.0f, 46.0f);
    self.resetButton = [self newButtonWithTitle:NSLocalizedString(@"ResetButtonName", nil) target:self selector:@selector(resetButtonTapped:) frame:resetButtonFrame image:whiteImage imagePressed:blueImage darkTextColor:NO];
    [self.view addSubview:self.resetButton];
    [self.resetButton setEnabled:NO];
    
    CGRect useButtonFrame = CGRectMake(175.0f, 390.0f, 115.0f, 46.0f);
    self.useButton = [self newButtonWithTitle:NSLocalizedString(@"UseButtonName", nil) target:self selector:@selector(useButtonTapped:) frame:useButtonFrame image:redImage imagePressed:blueImage darkTextColor:NO];
    [self.view addSubview:self.useButton];
    [self.useButton setEnabled:NO];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - LockViewDelegate
- (void)beforeUnlocking
{
    [self.resetButton setEnabled:NO];
    [self.useButton setEnabled:NO];
}

- (void)beganUnlock
{
    
}

- (void)unlocking
{
    
}

- (void)afterUnlock
{
    [self.resetButton setEnabled:YES];
    [self.useButton setEnabled:YES];
}

@end

 

转载于:https://my.oschina.net/yongbin45/blog/69559

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值