【问题标题】:How to create a passcode view iphone如何创建密码视图 iphone
【发布时间】:2010-12-24 23:27:14
【问题描述】:


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

这是我希望它必须做的:
- 如果用户正在设置他的密码,他必须输入两次,并且密码必须验证第二次输入的密码是否与第一次相同。
- 如果密码控制器被设置视图调用,例如设置密码,它必须在导航栏上有一个取消按钮,但如果在应用启动时调用它,则不能启用取消按钮。

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]; }

非常感谢!

【问题讨论】:

    标签: iphone view passwords controller screen


    【解决方案1】:

    另一种解决方案 KVPasscodeViewController(我的)可在此处获得:https://github.com/Koolistov/Passcode(BSD 许可证)。

    【讨论】:

      【解决方案2】:

      如果这对其他人有帮助,我用 GitHub 上的源代码解决了我的问题:PTPasscodeViewController
      我对其进行了一些更改以使其适应我的需要,现在效果很好:)

      如果你想使用它,在项目页面或文件中都有关于如何使用它的所有信息(如果你已经下载了);)

      希望对您有所帮助!

      P.S.:非常感谢 Lasha Dolidze 提供此代码!

      【讨论】:

      • 请注意 PTPasscodeViewController 是在 GPL 下获得许可的。
      • 本身还不错,但很多(如果不是全部)iOS 开发人员希望出售他们的应用程序并保持其闭源。 GPL 与此不兼容。
      【解决方案3】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-10-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-09
        • 2010-09-18
        相关资源
        最近更新 更多