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 ...
随机推荐
- nextjs —— jsx style 学习记录
作用域 全局 <style global jsx>{` .hero { width: 100%; color: #333; } .title { margin: 0; width: 100 ...
- MySQL5.7版本安装(压缩包形式)
1.去官网下载 MySQL 压缩包 2.配置环境变量 3.创建配置文件my.ini (放置 mysql-5.7.28-winx64 目录下) my.ini 配置文件 编写如下内容 [client] p ...
- [0, 1] 区间内 n 次独立随机事件的一些问题
问题一 证明:一根1米长的绳子,随机切成 $N$ 刀,变成($N+1$)根绳子,则最短的一根绳子长度的期望为 $\displaystyle \frac{1}{(N+1)^2}$. 证: 引理:当分成 ...
- TDOA基础之 delayed tx 实现说明
不论是在TWR 还是TDOA定位算法中,delayed tx 都会用到,这篇博文主要解析delayed tx 实现. 何为delayed tx? delayed tx 是延时发送,为何要延时?因为这个 ...
- Centos命令和Shell脚本问题集合
1.cat 错误写法 cat >> somefile.txt << EOF something EOF 原因:EOF 之后一定要是 ENTER(回车) 不能是空格或者其他.EO ...
- 使用JSP/Servlet技术开发新闻发布系统---JSP数据交互(二)
JSP内置对象application application对象 JSP常用的内置对象 对象的作用域 作用的分类 对象的作用域 page作用域 实例 //页面1 <% String name = ...
- CF369E Valera and Queries kdtree
给你一堆线段,求:一个区间内包含的本质不同线段种类数(只要线段有一部分在区间中就算是包含) 考虑容斥:总线段数-被那些没有询问的区间完全覆盖的数量. 用离线+树状数组数点或者 KDtree 数点即可. ...
- hihoCoder 1785
线性筛 + 递推 #include <bits/stdc++.h> , Mod = 1e9 + ; int n; int phi[N], prime[N], tot, ans; bool ...
- [TJOI2013]松鼠聚会 曼哈顿距离
[TJOI2013]松鼠聚会 luogu P3964 首先容易得到两点间距离是\(max(|x_1-x_2|, |y_1-y_2|)\)(即切比雪夫距离) 然后有个套路:原\((x,y)\)求曼哈顿距 ...
- java.lang.ClassNotFoundException: org.springframework.kafka.core.KafkaAdmin
<dependency> <groupId>org.springframework.kafka</groupId> <artifactId>spring ...