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 ...
随机推荐
- 在 windows 上安装 git 2.22
下载 by win 下载地址:https://git-scm.com/download/win 如下图.选择对应的版本下载: 安装 by win 1.双击下载好的git安装包.弹出提示框.如下图: 2 ...
- Linux下干净卸载mysql
1.首先查看mysql的安装情况 rpm -qa|grep -i mysql 显示之前安装了: MySQL-client-5.5.25a-1.rhel5 MySQL-server-5.5.25a-1. ...
- Tornado之Session实现
Tornado框架中,默认执行Handler的get/post等方法之前默认会执行 initialize方法,所以可以通过自定义的方式使得所有请求在处理前执行操作 import tornado.iol ...
- wsgiref 与 Django框架初识
前戏: Web框架的本质 我们可以这样理解:所有的Web应用本质上就是一个socket服务端,而用户的浏览器就是一个socket客户端,这样我们就可以自己实现Web框架 软件开发架构: c/s架构 客 ...
- CSP2019 D1T3 树上的数 (贪心+并查集)
题解 因为博主退役了,所以题解咕掉了.先放个代码 CODE #include<bits/stdc++.h> using namespace std; const int MAXN = 20 ...
- 批量给文件去BOM(百度网盘)
链接:https://pan.baidu.com/s/1jC8RkyC0xX1lA-zZjOyDsw 提取码:geko 第一步:浏览你要移除BOM编码的文件夹.第二步:点击移除bom,随后会弹出提示框 ...
- 配置interfaces
demo1 # This file describes the network interfaces available on your system # and how to activate th ...
- Selenium+Python附件上传
在自动化测试过程中,我们会经常遇到附件上传,而附件上传主要分为两种:input型.非input型,我们本章就两种不同类型的上传方式讲解: (1)input型 <input id="tx ...
- kvm 学习(二)镜像
Linux下 如何通过命令行使用现有的镜像创建.启动kvm虚拟机 这里假定已经创建好了相应的镜像: eg:我这里制作的镜像名称为zu1-centos7.img # ls zu1-centos7.img ...
- 重启hdfs集群的时候,报大量的gc问题。
问题现象: 2019-03-11 12:30:52,174 INFO org.apache.hadoop.util.JvmPauseMonitor: Detected pause in JVM or ...