说一下密码加密的实现方式
 
效果图:
 
 
 
 
 
实现方式:
 
主要说一下密码框的实现,这个密码框中间的四个数字其实是4个 UITextField ,然后通过键盘删除键 和TextFiled 的协议shouldChangeCharactersInRange.来判断输入的位置,代码如下;
 
 
 
直接上代码:
 
//
//  IDSGameRoomSecretView.h
//
//  Created by levi.duan on 2017/7/18.
//  Copyright © 2017年 Near. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "BaseViewController.h"

typedefvoid(^handleInputPasswordBlock)(NSString *password);

@interface IDSGameRoomSecretView : UIView

- (instancetype)initWithPasswordCallBack:(handleInputPasswordBlock)passwordCallback;

/**
 弹出说明视图
 */
- (void)showInputSecretView;

@end

 
 
 
 
 
 
//
//  IDSGameRoomSecretView.m
//  Near
//
//  Created by levi.duan on 2017/7/18.
//  Copyright © 2017年 Near. All rights reserved.
//

#import "IDSGameRoomSecretView.h"
#import "PZXVerificationTextField.h"

@interfaceIDSGameRoomSecretView()<UIGestureRecognizerDelegate,UITextFieldDelegate,PZXTextFieldDelegate>

@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UILabel *subtitleLabel;
@property (nonatomic,strong) UITextField *secretTextField;
@property (nonatomic,strong) UIButton *gameRoomBtn;
@property (nonatomic, strong) UIView *secretRoomView;
@property (nonatomic, strong) NSMutableArray *textFieldArray;
@property (nonatomic , copy) handleInputPasswordBlock onHandlePasswordCallBack;

@end

@implementation IDSGameRoomSecretView

- (instancetype)initWithPasswordCallBack:(handleInputPasswordBlock)passwordCallback
{
    if (self = [superinit]) {
        self.onHandlePasswordCallBack = passwordCallback;
    }
   
    returnself;
}

- (void)showInputSecretView
{

    self.backgroundColor = [UIColorcolorWithRed:0green:0blue:0alpha:0.7];

    [[AppDelegatemainWindow] addSubview:self];
    [self.inputViewbecomeFirstResponder];
   
    self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
   
    UITapGestureRecognizer *selfRecognizer = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(removeView)];
    self.userInteractionEnabled = YES;
    [selfaddGestureRecognizer:selfRecognizer];
    selfRecognizer.delegate = self;
   
    self.secretRoomView = [[UIViewalloc] initWithFrame:CGRectMake(0, 0, 510/2, 380/2)];
    self.secretRoomView.centerY = SCREEN_HEIGHT/2;
    self.secretRoomView.centerX = SCREEN_WIDTH/2;
    self.secretRoomView.backgroundColor = [UIColorwhiteColor];
   
    self.secretRoomView.centerY = SCREEN_HEIGHT/2-50;
 
   

    _titleLabel = [[UILabelalloc] initWithFrame:CGRectMake(0, 50/2, 0, 0)];
    _titleLabel.text = @"房间已加锁";
    _titleLabel.textColor = NF_Color_C3;
    _titleLabel.font = [UIFontsystemFontOfSize:Near_Final_Font_T6];
    [_titleLabelsizeToFit];
    _titleLabel.centerX = self.secretRoomView.frame.size.width/2;
    [self.secretRoomViewaddSubview:_titleLabel];
   
    _subtitleLabel = [[UILabelalloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(self.titleLabel.frame)+10, 0, 0)];
    _subtitleLabel.text = @"输入房间密码";
    _subtitleLabel.textColor = NF_Color_C10;
    _subtitleLabel.font = [UIFontsystemFontOfSize:Near_Final_Font_T9];
    [_subtitleLabelsizeToFit];
    _subtitleLabel.centerX = self.secretRoomView.frame.size.width/2;
    [self.secretRoomViewaddSubview:_subtitleLabel];
   
    self.textFieldArray = [NSMutableArrayarray];
    NSArray *views = [selfsubviews];
    for (UITextField *tf in views) {
        [tf removeFromSuperview];
    }
   
    for (int i=0;i<4;++i) {
        PZXVerificationTextField *tf = [[PZXVerificationTextFieldalloc] initWithFrame:CGRectMake(70/2+i*70/2+15*i, CGRectGetMaxY(self.subtitleLabel.frame)+15, 70/2, 70/2)];
        [tf setFont:[UIFontsystemFontOfSize:Near_Final_Font_T5]];
        [tf setTextColor:NF_Color_C4];
        tf.backgroundColor = [UIColorclearColor];
        tf.layer.borderWidth = 0.5;
        tf.layer.borderColor = NF_Color_C9.CGColor;
        tf.layer.cornerRadius = 5.f;
        tf.layer.masksToBounds = YES;
        tf.tintColor =[UIColorclearColor];
        tf.tag = 100+i;
        tf.keyboardType = UIKeyboardTypeNumberPad;
        tf.textAlignment = NSTextAlignmentCenter;
        tf.delegate = self;
        tf.pzx_delegate = self;
        [self.secretRoomViewaddSubview:tf];
        [self.textFieldArraycl_addObject:tf];
        [tf becomeFirstResponder];
    }
   
    self.gameRoomBtn = [[UIButtonalloc] initWithFrame:CGRectMake(0, 270/2, 228/2, 68/2)];
    self.gameRoomBtn.centerX = self.secretRoomView.frame.size.width/2;
   
    [self.gameRoomBtnsetTitle:@"确定"forState:UIControlStateNormal];
    [self.gameRoomBtn.titleLabelsetFont:[UIFontsystemFontOfSize:Near_Final_Font_T5]];
    [self.gameRoomBtn.titleLabelsetTextColor:NF_Color_C1];
    self.gameRoomBtn.backgroundColor = NF_Color_C27;
    [self.gameRoomBtnaddTarget:selfaction:@selector(interRoomVoid) forControlEvents:UIControlEventTouchUpInside];
    self.gameRoomBtn.layer.cornerRadius = 5.0f;
    self.gameRoomBtn.layer.masksToBounds = YES;
   
    [self.secretRoomViewaddSubview:self.gameRoomBtn];
   
    [selfaddSubview:self.secretRoomView];
   
    self.secretRoomView.layer.cornerRadius = 10.f;
    self.secretRoomView.layer.masksToBounds = YES;
   
   
}

#pragma mark - Public Methods

/*
- (void)showDalog
{
    [[AppDelegate mainWindow] addSubview:self];
    [self.inputView becomeFirstResponder];
}
 */

- (void)removeView
{
    [selfremoveFromSuperview];
}

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
   
    textField.text = string;
   
    if (textField.text.length > 0) {//防止退格第一个的时候往后跳一格
       
        if (textField.tag<  [[_textFieldArraylastObject] tag]) {
           
            UITextField *newTF =  (UITextField *)[selfviewWithTag:textField.tag+1];
           
            [newTF becomeFirstResponder];
        }
    }
    returnNO;
}

//点击退格键的代理
#pragma mark - PZXTextFieldDelegate
-(void)PZXTextFieldDeleteBackward:(PZXVerificationTextField *)textField{
   
    if (textField.tag > [[_textFieldArrayfirstObject] tag]) {
       
        UITextField *newTF =  (UITextField *)[selfviewWithTag:textField.tag-1];
        newTF.text = @"";
        [newTF becomeFirstResponder];
    }
   
   
}

- (void)interRoomVoid
{
    [selfgetVertificationCode];
}

-(void)getVertificationCode{ //获取验证码方法
   
    NSString *str = [NSStringstring];
   
    for (int i = 0; i<_textFieldArray.count; i++) {
        str = [str stringByAppendingString:[NSStringstringWithFormat:@"%@",(UITextField *)[_textFieldArray[i] text]]];
    }
    if (self.onHandlePasswordCallBack) {
        self.onHandlePasswordCallBack(str);
    }
    [selfremoveView];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
   
    for (UITextField *tf inself.textFieldArray) {
       
        [tf resignFirstResponder];
    }
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([touch.viewisDescendantOfView:self.secretRoomView]) {
        returnNO;
    }
    returnYES;
}

@end

 
//
//  PZXVerificationTextField.h
//  Near
//
//  Created by levi.duan on 2017/7/19.
//  Copyright © 2017年 Near. All rights reserved.
//

#import <UIKit/UIKit.h>

@classPZXVerificationTextField;//要class一下不然代理里面无法识别

@protocol PZXTextFieldDelegate <NSObject>

- (void)PZXTextFieldDeleteBackward:(PZXVerificationTextField *)textField;

@end

@interface PZXVerificationTextField : UITextField

@property (nonatomic, assign)id<PZXTextFieldDelegate> pzx_delegate;

@end

 
 
 
//
//  PZXVerificationTextField.m
//  Near
//
//  Created by levi.duan on 2017/7/19.
//  Copyright © 2017年 Near. All rights reserved.
//

#import "PZXVerificationTextField.h"

@implementation PZXVerificationTextField

-(void)deleteBackward{
    [superdeleteBackward];
    if ([self.pzx_delegaterespondsToSelector:@selector(PZXTextFieldDeleteBackward:)]) {
       
        [self.pzx_delegatePZXTextFieldDeleteBackward:self];
    }
   
   
}

@end

 

iOS密码框的实现方式的更多相关文章

  1. iOS密码框实现(二)取消确定按钮

    由于将确定按钮去掉了,所以需要重新修改下代码,当输入第四个数字时,自动进入房间.   iOS 密码框效果图:     实现方式:   首先声明一个block初始化方法,因为这只是个框框,并不需要处理网 ...

  2. 表单form的属性,单行文本框、密码框、单选多选按钮

    基础表单结构: <body> <h1> <hr /> <form action="" name="myFrom" en ...

  3. iOS弹框

    IOS 弹框 如果直接弹出一个自定义的视图 可以选用第三方: MJPopup 弹出: if(!bandview) { bandview=[[[NSBundle mainBundle]loadNibNa ...

  4. WPF文本框密码框添加水印效果

    WPF文本框密码框添加水印效果 来源: 阅读:559 时间:2014-12-31 分享: 0 按照惯例,先看下效果 文本框水印 文本框水印相对简单,不需要重写模板,仅仅需要一个VisualBrush ...

  5. [Asp.net]说说密码框和只读框

    作者:Wolfy出处:http://www.cnblogs.com/wolf-sun/ 引言 最近负责了一个公司的小项目,从前台到后代,都是自己搞的,为一个客户弄一个信息管理的小系统,虽然对界面什么的 ...

  6. Qt之密码框不可选中、复制、粘贴、无右键菜单等

    简述 在做用户登录.修改密码的时候,往往会用到密码框,其中一些功能要求与普通的输入框不同,例如:不能选中.复制.粘贴.无右键菜单等功能,当然设置密码不可见是必须的! 下面介绍两种方式来实现相同的效果. ...

  7. WPF 之 文本框及密码框添加水印效果

    1.文本框添加水印效果 文本框水印相对简单,不需要重写模板,仅仅需要一个 VisualBrush 和触发器验证一下Text是否为空即可. <TextBox Name="txtSerac ...

  8. 【Qt】Qt之密码框不可选中、复制、粘贴、无右键菜单等【转】

    简述 在做用户登录.修改密码的时候,往往会用到密码框,其中一些功能要求与普通的输入框不同,例如:不能选中.复制.粘贴.无右键菜单等功能,当然设置密码不可见是必须的! 下面介绍两种方式来实现相同的效果. ...

  9. Ios 弹框 MJPopup,KxMenu

    IOS 弹框 如果直接弹出一个自定义的视图 可以选用第三方: MJPopup 弹出: if(!bandview) { bandview=[[[NSBundle mainBundle]loadNibNa ...

随机推荐

  1. 【23.24%】【codeforces 629C】Famil Door and Brackets

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. C++ Primer章课后编程问题

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZ3V1Z2xlMjAxMA==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  3. 解决gdal集成libkml的链接错误

    作者:朱金灿 来源:http://blog.csdn.net/clever101 gdal库在集成libkml出现一些链接错误: 1>libkmldomD.lib(kml_factory.obj ...

  4. yii2.0表单《《提交》》变量设置

    public $enableCsrfValidation = false;

  5. wpf中xaml的类型转换器与标记扩展

    原文:wpf中xaml的类型转换器与标记扩展 这篇来讲wpf控件属性的类型转换器 类型转换器 类型转换器在asp.net控件中已经有使用过了,由于wpf的界面是可以由xaml组成的,所以标签的便利也需 ...

  6. 学习Hadoop和Spark的好的资源

    1. 官网http://spark.apache.org 有各种资源链接: 2. 总结得很好的个人博客[从零开始学Hadoop系列]1)初识http://blog.csdn.net/u01016816 ...

  7. WPF中取得系统字体列表

    原文:WPF中取得系统字体列表 在GDI+中,我们可以通过如下方式取得系统所有字体: foreach(FontFamily f in FontFamily.Families){   // 处理代码} ...

  8. poj 3390 Print Words in Lines 动态规划

    意甲冠军: 给n每行长度和字符可放置最大数量字m,每一行产生值至(m-x)^2,x是一个字符上线人数(包含空话之间格).为了让所有的完成,产生的话值最小和. 分析: 动态规划非常重要的就是状态的定义, ...

  9. c#开发移动APP-Xamarin入门

    原文:c#开发移动APP-Xamarin入门 如果您在.net环境下做开发,并且对WPF技术有一定了解及应用,同时也想进入移动App开发领域,推荐使用Xamarin开发移动应用 关于Xamarin不做 ...

  10. Android - 小的特点 - 使用最新版本ShareSDK手册分享(分享自己定义的接口)

    前太实用Share SDK很快分享,但官员demo快捷共享接口已被设置死,该公司的产品还设计了自己的份额接口,这需要我手动共享. 读了一堆公文,最终写出来,行,废话,进入主题. 之前没实用过Share ...