我想在我的应用程序中添加密码锁...
我创建了视图,但我不知道如何让它工作......
这是我必须做的事情:
- 如果用户正在设置其密码,则必须键入两次,并且代码必须验证第二次输入的密码是否与第一次相同。
- 如果设置视图调用密码控制器(例如,设置密码),则导航栏上必须有取消按钮,但如果在应用启动时调用,则不能启用取消按钮。
summaryLabel是显示“密码不匹配”等消息的标签。请重试。当密码与先前写入或保存的密码不同时。
EDIT1:如何使用textField:shouldChangeCharactersInRange:replacementString方法执行此操作?
这是代码:
#import "PasscodeController.h"
@implementation PasscodeController
@synthesize panelView; @synthesize summaryLabel; @synthesize titleLabel; @synthesize textField1; @synthesize textField2; @synthesize textField3; @synthesize textField4; @synthesize hiddenTF;
-(void)viewDidLoad { self.title = @"Passcode"; self.view.backgroundColor = [UIColor groupTableViewBackgroundColor]; titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 22, 270, 30)]; titleLabel.font = [UIFont boldSystemFontOfSize:15]; titleLabel.textAlignment = UITextAlignmentCenter; titleLabel.textColor = [UIColor colorWithRed:66.0/255.0 green:85.0/255.0 blue:102.0/255.0 alpha:1.0]; titleLabel.backgroundColor = [UIColor clearColor]; [self.view addSubview:titleLabel]; [titleLabel release];
summaryLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 130, 270, 40)]; summaryLabel.font = [UIFont boldSystemFontOfSize:12]; summaryLabel.numberOfLines = 0; summaryLabel.baselineAdjustment = UIBaselineAdjustmentNone; summaryLabel.textAlignment = UITextAlignmentCenter; summaryLabel.textColor = [UIColor colorWithRed:66.0/255.0 green:85.0/255.0 blue:102.0/255.0 alpha:1.0]; summaryLabel.backgroundColor = [UIColor clearColor]; [self.view addSubview:summaryLabel]; [summaryLabel release];
textField1 = [[UITextField alloc] initWithFrame:CGRectMake(25, 60, 60, 60)]; textField1.borderStyle = UITextBorderStyleBezel; textField1.textColor = [UIColor blackColor]; textField1.textAlignment = UITextAlignmentCenter; textField1.font = [UIFont systemFontOfSize:41]; textField1.secureTextEntry = YES; textField1.backgroundColor = [UIColor whiteColor]; textField1.keyboardType = UIKeyboardTypeNumberPad; [self.view addSubview:textField1]; [textField1 release];
textField2 = [[UITextField alloc] initWithFrame:CGRectMake(95, 60, 60, 60)]; textField2.borderStyle = UITextBorderStyleBezel; textField2.textColor = [UIColor blackColor]; textField2.textAlignment = UITextAlignmentCenter; textField2.font = [UIFont systemFontOfSize:41]; textField2.secureTextEntry = YES; textField2.backgroundColor = [UIColor whiteColor]; textField2.keyboardType = UIKeyboardTypeNumberPad; [self.view addSubview:textField2]; [textField2 release];
textField3 = [[UITextField alloc] initWithFrame:CGRectMake(165, 60, 60, 60)]; textField3.borderStyle = UITextBorderStyleBezel; textField3.textColor = [UIColor blackColor]; textField3.textAlignment = UITextAlignmentCenter; textField3.font = [UIFont systemFontOfSize:41]; textField3.secureTextEntry = YES; textField3.backgroundColor = [UIColor whiteColor]; textField3.keyboardType = UIKeyboardTypeNumberPad; [self.view addSubview:textField3]; [textField3 release];
textField4 = [[UITextField alloc] initWithFrame:CGRectMake(235, 60, 60, 60)]; textField4.borderStyle = UITextBorderStyleBezel; textField4.textColor = [UIColor blackColor]; textField4.textAlignment = UITextAlignmentCenter; textField4.font = [UIFont systemFontOfSize:41]; textField4.secureTextEntry = YES; textField4.backgroundColor = [UIColor whiteColor]; textField4.keyboardType = UIKeyboardTypeNumberPad; [self.view addSubview:textField4]; [textField4 release];
hiddenTF = [[UITextField alloc] initWithFrame:CGRectZero]; hiddenTF.hidden = YES; hiddenTF.delegate = self; hiddenTF.keyboardType = UIKeyboardTypeNumberPad; [self.view addSubview:hiddenTF]; [hiddenTF release]; [hiddenTF becomeFirstResponder]; }
非常感谢!
答案 0 :(得分:4)
另一个解决方案,KVPasscodeViewController(我的),可在此处获取:https://github.com/Koolistov/Passcode(BSD许可证)。
答案 1 :(得分:3)
如果这对其他人有帮助,我在GitHub上使用此源代码解决了我的问题:PTPasscodeViewController。
我改变它以适应我的需要,现在工作得很好:)
如果您想使用它,有关于如何在项目页面或文件中使用它的所有信息(如果您已下载);)
希望这有帮助!
P.S。:非常感谢Lasha Dolidze提供此代码!
答案 2 :(得分:2)