iphone - 如何创建 iphone 密码查看

标签 iphone view passwords controller screen


我想在我的应用程序中添加密码锁...
我创建了 View ,但我不知道如何让它工作......

这就是我希望它必须做的:
- 如果用户设置密码,则必须输入两次,并且代码必须验证第二次输入的密码是否与第一次相同。
- 如果密码 Controller 由设置 View 调用,例如,为了设置密码,它必须在导航栏上有一个取消按钮,但如果在应用程序启动时调用它,则不得启用取消按钮。

summaryLabel 是显示“密码不匹配。请重试”之类消息的标签。当密码与之前写入或保存的密码不同时。

编辑1:如何使用textField:shouldChangeCharactersInRange:replacementString方法来执行此操作?

这是代码:

#import "PasscodeController.h"<p></p>

<p>@implementation PasscodeController</p>

<p>@synthesize panelView;
@synthesize summaryLabel;
@synthesize titleLabel;
@synthesize textField1;
@synthesize textField2;
@synthesize textField3;
@synthesize textField4;
@synthesize hiddenTF;</p>

<p>-(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];</p>

<p>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];</p>

<p>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];</p>

<p>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];</p>

<p>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];</p>

<p>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];</p>

hiddenTF = [[UITextField alloc] initWithFrame:CGRectZero]; hiddenTF.hidden = YES; hiddenTF.delegate = self; hiddenTF.keyboardType = UIKeyboardTypeNumberPad; [self.view addSubview:hiddenTF]; [hiddenTF release]; [hiddenTF becomeFirstResponder]; }

非常感谢!

最佳答案

另一个解决方案,KVPasscodeViewController(我的),可以在这里找到:https://github.com/Koolistov/Passcode (BSD 许可证)。

关于iphone - 如何创建 iphone 密码查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4528707/

相关文章:

ios - 在 iTunes 中更新后的相同应用程序

android - CSS:应用多个媒体查询

android - react-native ViewPagerAndroid peek 属性

asp.net - 在非关系数据库中创建 View

android - 我可以为 android 中的 View 设置类似 "tooltip"的内容吗?

laravel - 尝试在 Laravel 中重置密码时,此密码重置 token 无效

attributes - Unboundid LDAP 域属性

ios - 部署目标为 7.0 和 Xcode 7.1-7.2 的 iPhone4 中的启动屏幕为黑色

c - 这个c程序有可能破解密码吗?

ios - 如何处理 iOS 11 Navigation BarButtonItems 错误?