一,工程结构,如下图所示:

二,代码

PasswordInputWindow.h

#import <UIKit/UIKit.h>

@interface PasswordInputWindow : UIWindow

+(PasswordInputWindow *)shareInstance;
-(void)show; @end

PasswordInputWindow.m

#import "PasswordInputWindow.h"

@implementation PasswordInputWindow
{
UITextField *_textField;
} +(PasswordInputWindow *)shareInstance
{
static id shareInstance=nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken,^{ shareInstance=[[self alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
});
return shareInstance;
}
-(id)initWithFrame:(CGRect)frame
{
self=[super initWithFrame:frame];
if (self) { UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(10, 50, 200, 20)];
label.text=@"请输入密码";
[self addSubview:label]; UITextField *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 yellowColor];
_textField=textField;
}
return self;
}
-(void)show
{
[self makeKeyAndVisible];
self.hidden=NO;
}
-(void)completeButtonPressed:(id)sender{
if ([_textField.text isEqualToString:@"abcd"]) {
[_textField resignFirstResponder];
[self resignFirstResponder];
self.hidden=YES;
}else{
[self showErrorAlertView];
}
}
-(void)showErrorAlertView
{
UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:nil message:@"密码错误,正确密码是abcd" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertView show];
}
@end

三,运行效果。

参考资料 :

《iOS开发进阶》-唐巧

【读书笔记】iOS-UIWindow-密码框的更多相关文章

  1. UIwindow ---密码框

    程序运行显示结果如下 : 验证密码输入错误显示如下: 代码如下 : 1> ////  PasswordInputWindow.m//  UIWindow--密码框////  Created by ...

  2. [读书笔记]iOS 7 UI设计 对比度

    好久没写随笔了,最近在读<iOS 7 byTutorials>,很不错,推荐给大家. 每一个好的程序员也都是一个设计师,不懂设计的程序员不是好的CTO.哈哈,开个小玩笑. iOS 7设计的 ...

  3. 读书笔记-iOS核心动画高级技巧

    如果不使用+imageNamed:,那么把整张图片绘制到CGContext可能是最佳的方式了. 这里我们利用了CALayer的KVC来存储和检索任意的值,将图层和索引打标签. 使用KVC打标签

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

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

  5. iOS密码框的实现方式

    说一下密码加密的实现方式   效果图:           实现方式:   主要说一下密码框的实现,这个密码框中间的四个数字其实是4个 UITextField ,然后通过键盘删除键 和TextFile ...

  6. iPhone与iPad开发实战读书笔记

    iPhone开发一些读书笔记 手机应用分类1.教育工具2.生活工具3.社交应用4.定位工具5.游戏6.报纸和杂志的阅读器7.移动办公应用8.财经工具9.手机购物应用10.风景区相关应用11.旅游相关的 ...

  7. 锋利的jQuery读书笔记---选择器

    前段时间入手了锋利的jQuery(第二版),想着加强下自己的js能力,可前段时间一只在熟悉Spring和Hibernate.最近抽时间开始读这本书了,随便也做了些记录. 读书的过程是边看边代码测试,所 ...

  8. <读书笔记> 代码整洁之道

    概述      1.本文档的内容主要来源于书籍<代码整洁之道>作者Robert C.Martin,属于读书笔记. 2.软件质量,不仅依赖于架构和项目管理,而且与代码质量紧密相关,本书提出一 ...

  9. WPF,Silverlight与XAML读书笔记第四十三 - 多媒体支持之文本与文档

    说明:本系列基本上是<WPF揭秘>的读书笔记.在结构安排与文章内容上参照<WPF揭秘>的编排,对内容进行了总结并加入一些个人理解. Glyphs对象(WPF,Silverlig ...

随机推荐

  1. Enjoy Android

    大趋势所迫,开始学习Android, @mark一下

  2. fzu 2107 Hua Rong Dao(状态压缩)

    Problem 2107 Hua Rong Dao Accept: 106    Submit: 197 Time Limit: 1000 mSec    Memory Limit : 32768 K ...

  3. codeforces MUH and Cube Walls

    题意:给定两个序列a ,b, 如果在a中存在一段连续的序列使得 a[i]-b[0]==k, a[i+1]-b[1]==k.... a[i+n-1]-b[n-1]==k 就说b串在a串中出现过!最后输出 ...

  4. codeforce No to Palindromes!(枚举)

    /* 题意:给定一个字符串中没有任何长度>1的回文子串!求按照字典序的该串的下一个字符串 也不包含长度>1的任何回文子串! 思路:从最低位进行枚举,保证第i位 不与 第 i-1位和第 i- ...

  5. maven -- 问题解决(一)解决eclipse中maven项目出现的问题

    配置项目时出现的错误: error: Cannot change version of project facet Dynamic Web Module to 2.5. error: One or m ...

  6. ruby -- 基础学习(四)TimeDate处理

     TimeDate格式化输出: DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d %H:%M:%S').to_s #就是按照2013-8-16 16:4 ...

  7. DateTimePicker 控件的格式设置

    DateTimePicker 控件的格式设置 CustomFormat属性设置 : yyyy-MM-dd HH:mm:ss  月大写M,分钟小写m,小时H代表24小时计算,h代表12小时计算yyyy- ...

  8. apple Swift教程大全,希望对你有帮助!

    1)apple Swift编程入门文档- http://gashero.iteye.com/blog/2075324 一位大神写的关于Swift的一些介绍和简单的使用,里面介绍了Swift和其他语言的 ...

  9. Linux磁盘操作命令

    查看本地磁盘使用情况:df或者df -l单位为k 容量便于查看,以1024单位换算为M或者G等:df -h或者df -lh 以1000为单位换算:df -H 显示文件系统类型:df -T 显示指定文件 ...

  10. Hibernate中延迟加载和缓存

    什么是延迟加载? 延迟加载是指当应用程序想要从数据库获取对象时(在没有设置lazy属性值为false),Hibernate只是从数据库获取符合条件的对象的OId从而生成代理对象,并没有加载出对象 访问 ...