gpt4 book ai didi

iphone - 如何创建 iphone 密码查看

转载 作者:行者123 更新时间:2023-12-03 20:22:23 26 4
gpt4 key购买 nike


我想在我的应用程序中添加密码锁...
我创建了 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com