UIwindow ---密码框
程序运行显示结果如下 :
验证密码输入错误显示如下:
代码如下 :
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 ---密码框的更多相关文章
- jquery更改输入框type为密码框password
很蛋疼的一个问题: <input type="text" id="e1" value="123" /> 用juqery将文本框变 ...
- 模拟placeholder支持ie8以下处理了密码框只读的问题
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- jq实现 禁止对密码框中的内容进行复制、剪切和粘贴操作
$(function () { $("input:password").on("copy cut paste", function (e) { return f ...
- 表单form的属性,单行文本框、密码框、单选多选按钮
基础表单结构: <body> <h1> <hr /> <form action="" name="myFrom" en ...
- WPF文本框密码框添加水印效果
WPF文本框密码框添加水印效果 来源: 阅读:559 时间:2014-12-31 分享: 0 按照惯例,先看下效果 文本框水印 文本框水印相对简单,不需要重写模板,仅仅需要一个VisualBrush ...
- [Asp.net]说说密码框和只读框
作者:Wolfy出处:http://www.cnblogs.com/wolf-sun/ 引言 最近负责了一个公司的小项目,从前台到后代,都是自己搞的,为一个客户弄一个信息管理的小系统,虽然对界面什么的 ...
- JAVA 文本框、密码框、标签
//文本框,密码框,标签 import java.awt.*; import javax.swing.*; public class Jiemian5 extends JFrame{ JPanel m ...
- Qt之密码框不可选中、复制、粘贴、无右键菜单等
简述 在做用户登录.修改密码的时候,往往会用到密码框,其中一些功能要求与普通的输入框不同,例如:不能选中.复制.粘贴.无右键菜单等功能,当然设置密码不可见是必须的! 下面介绍两种方式来实现相同的效果. ...
- WPF 之 文本框及密码框添加水印效果
1.文本框添加水印效果 文本框水印相对简单,不需要重写模板,仅仅需要一个 VisualBrush 和触发器验证一下Text是否为空即可. <TextBox Name="txtSerac ...
随机推荐
- 阿里云上遇到: virtual memory exhausted: Cannot allocate memory
# dd if=/dev/zero of=/swap bs=1024 count=1M Format the swap file: # mkswap /swap Enable the swap fil ...
- JS闭包是什么?
闭包是js开发惯用的技巧,什么是闭包? 闭包指的是:能够访问另一个函数作用域的变量的函数. 清晰的讲:闭包就是一个函数,这个函数能够访问其他函数的作用域中的变量. function outer(){ ...
- Django REST framework+Vue 打造生鲜电商项目(笔记十一)
(form: http://www.cnblogs.com/derek1184405959/p/8886796.html 有修改) 十四.social_django 集成第三方登录 1.申请应用 进入 ...
- java获取远程服务器应用程序服务状态
package lct.conference.test; import java.io.BufferedReader; import java.io.IOException; import java. ...
- 差分约束 4416 FFF 团卧底的后宫
/* 4416 FFF 团卧底的后宫 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 你在某日收到了 FFF ...
- CF455C Civilization
嘟嘟嘟 水题一道,某谷又恶意评分. 合并无非是将两棵树的直径的中点连一块,记原来两棵树的直径为\(d_1, d_2\),那么新的树的直径就是\(max(d_1, d_2, \lceil \frac{d ...
- Bzoj 2733: [HNOI2012]永无乡(线段树+启发式合并)
2733: [HNOI2012]永无乡 Time Limit: 10 Sec Memory Limit: 128 MB Description 永无乡包含 n 座岛,编号从 1 到 n,每座岛都有自己 ...
- [转]引用模板类中定义的类型(用typedef或using)以及auto、decltype、typename的使用
一.背景 使用typedef或者using定义类型别名是非常常见的手段,在c++里面,有时为了封装性,模块性等原因还会在某一个namespace或者class内部定义类型别名. 最近在写c++代码的时 ...
- express搭建web服务器、路由、get、post请求、multer上传文件、EJS模板引擎的使用
express官网 postman工具下载地址 multer的npm文档地址 express模板引擎怎么使用 地址:http://www.expressjs.com.cn/guide/using- ...
- docker安装mysql5.7 数据挂载
docker安装mysql5.7,并数据卷挂载到主机 # docker 中下载 mysql docker pull mysql:5.7 #启动 docker run --name mysql3306 ...