程序运行显示结果如下 :

验证密码输入错误显示如下:

代码如下 :

1>

//
//  PasswordInputWindow.m
//  UIWindow--密码框
//
//  Created by mac1 on 15/10/5.
//  Copyright (c) 2015年 www.iphonetrain.com. All rights reserved.
//

#import "PasswordInputWindow.h"

@interface PasswordInputWindow  ()

@property (nonatomic,strong)UITextField *textField;

@end
@implementation PasswordInputWindow

static id instance = nil;

//单例方法创建对象
+ (PasswordInputWindow *)shareInstance
{
    //GCD实现单例
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken,^{
      
       instance =[[self alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        
    });
    
    return instance;
}

- (id)initWithFrame:(CGRect)frame
{
    if (self == [super initWithFrame:frame]) {
        
        //创建Label
        UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(10, 50, 200, 20)];
        label.text=@"请输入密码";
        [self addSubview:label];
        
        
        //创建输入框
        _textField=[[UITextField alloc]initWithFrame:CGRectMake(10, 80, 200, 20)];
        _textField.backgroundColor=[UIColor whiteColor];
        _textField.secureTextEntry=YES;
        [self addSubview:_textField];
        
        
        //创建按钮
        UIButton *button=[[UIButton alloc] initWithFrame:CGRectMake(10, 110, 200, 44)];
        [button setBackgroundColor:[UIColor blueColor]];
        button.titleLabel.textColor=[UIColor blackColor];
        [button setTitle:@"确定" forState:UIControlStateNormal];
        [button addTarget:self action:@selector(completeButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];

self.backgroundColor=[UIColor greenColor];
    }
    return self;
}

//显示
- (void)show
{
    
    //使窗口可显示
    [self makeKeyAndVisible];

//窗口不隐藏
    self.hidden=NO;
    
}

//密码错误调用的方法
-(void)showErrorAlertView
{
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"输入密码错误" message:@"密码输入错误" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
    
    [alertView show];
    
}

//"确定"按钮触发的方法
- (void)completeButtonPressed:(id)sender{
    if ([_textField.text isEqualToString:@"abcd"]) {
        
        //键盘失去第一响应
        [_textField resignFirstResponder];
        //窗口为第一响应者
        [self resignFirstResponder];
        self.hidden=YES;
    }else{
        
        [self showErrorAlertView];
    }
}
@end

2>

外部控制器调用 :

//
//  ViewController.m
//  UIWindow--密码框
//
//  Created by mac1 on 15/10/5.
//  Copyright (c) 2015年 www.iphonetrain.com. All rights reserved.
//

#import "ViewController.h"
#import "PasswordInputWindow.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    //单例创建对象
    PasswordInputWindow *passView = [PasswordInputWindow shareInstance];

//让窗口显示
    [passView show];
        
}
@end

UIwindow ---密码框的更多相关文章

  1. jquery更改输入框type为密码框password

    很蛋疼的一个问题: <input type="text" id="e1" value="123" /> 用juqery将文本框变 ...

  2. 模拟placeholder支持ie8以下处理了密码框只读的问题

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. jq实现 禁止对密码框中的内容进行复制、剪切和粘贴操作

    $(function () { $("input:password").on("copy cut paste", function (e) { return f ...

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

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

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

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

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

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

  7. JAVA 文本框、密码框、标签

    //文本框,密码框,标签 import java.awt.*; import javax.swing.*; public class Jiemian5 extends JFrame{ JPanel m ...

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

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

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

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

随机推荐

  1. 安装gitlab并汉化

    简介: GitLab是一个利用Ruby on Rails开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目. 它拥有与GitHub类似的功能,能够浏览源代码 ...

  2. DateTime函数

    一.初始化: DateTime dt = , , ); DateTime dt1 = DateTime.Now; DateTime dt2 = DateTime.Today; DateTime dt3 ...

  3. IDEA2018创建SpringBoot无法连接https://start.spring.io

    这是由于spring-boot需要访问https://start.spring.io外网,但是由于国内的局域网限制导致的. 解决办法: 进入到IDEA的setting 搜索 HTTP Proxy 选择 ...

  4. 006_Python3 数字(Number)

    1. Python 数字数据类型用于存储数值. 数据类型是不允许改变的,这就意味着如果改变数字数据类型的值,将重新分配内存空间.   以下实例在变量赋值时 Number 对象将被创建: var1 = ...

  5. jQuery相关方法9----事件相关

    一.事件冒泡和阻止事件冒泡 <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></s ...

  6. PHP sha1()函数

    <!DOCTYPE html> <html> <body> <?php $str = "dashu"; echo sha1($str); ...

  7. ros python 四元数 转 欧拉角

    import sysimport math w = -0.99114048481x = -0.00530699081719y = 0.00178255140781z = -0.133612662554 ...

  8. ICEM-圆锥的一种画法

    原视频下载地址:https://yunpan.cn/cqK53dKBnduM9  访问密码 42be ​

  9. [转]Python3之max key参数学习记录

    Python3之max key参数学习记录 转自https://www.cnblogs.com/zhangwei22/p/9892422.html 今天用Python写脚本,想要实现这样的功能:对于给 ...

  10. BitmapFactory: inSampleSize 的一些思考

    一. BitmapFactory.Options 中inSampleSize的取值问题 关于inSampleSize的取值问题Google已经给出了一个推荐的算法:(https://developer ...