iOS仿支付宝输入支付密码框

类似于下图这样的输入框,并实现其功能

实现这个页面,其中输入框部分为核心问题,仅针对输入框部分进行解读 下面代码只看其功能不看其位置信息

    topTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, wayLine.bottom, passView.width, topLabel.height*2)];
    topTextField.hidden = YES;
    topTextField.keyboardType = UIKeyboardTypePhonePad;
    [topTextField addTarget:self action:@selector(txChange:) forControlEvents:UIControlEventEditingChanged];
    [passView addSubview:topTextField];
    
    
    for (int i = 0; i < 6; i++)
    {
        UITextField *pwdLabel = [[UITextField alloc] initWithFrame:CGRectMake(20+i*(passView.width - 40)/6, wayLine.bottom + 10, (passView.width - 40)/6, (passView.width - 40)/6)];
        pwdLabel.layer.borderColor = [TncTool colorWithHexString:@"d2d2d2"].CGColor;
        pwdLabel.enabled = NO;
        pwdLabel.backgroundColor = [UIColor whiteColor];
        pwdLabel.textAlignment = NSTextAlignmentCenter;//居中
        pwdLabel.secureTextEntry = YES;//设置密码模式
        pwdLabel.layer.borderWidth = 1;
        [passView addSubview:pwdLabel];
        
        [textMuArray addObject:pwdLabel];
    }

实现topTextField添加的事件

- (void)txChange:(UITextField *)textField{
    NSString *password = textField.text;
    
    if (password.length == textMuArray.count)
    {
        [textField resignFirstResponder];//隐藏键盘
    }
    
    for (int i = 0; i < textMuArray.count; i++)
    {
        UITextField *pwdtx = [textMuArray objectAtIndex:i];
        if (i < password.length)
        {
            NSString *pwd = [password substringWithRange:NSMakeRange(i, 1)];
            pwdtx.text = pwd;
        }
        
    }
    
    if (password.length == 6)
    {
        [topTextField resignFirstResponder];
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"输入的密码是" message:password delegate:nil cancelButtonTitle:@"完成" otherButtonTitles:nil, nil];
        [alert show];
    }

}

这样就解决的输入框的问题,至于具体的逻辑就要看产品狗的需求了

 

转载于:https://www.cnblogs.com/nsjelly/p/5776351.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值