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 ...
随机推荐
- 分布式系统:CAP理论
无论你是一个系统架构师,还是一个普通开发,当你开发或者设计一个分布式系统的时候,CAP理论是无论如何也绕不过去的.本文就来介绍一下到底什么是CAP理论,如何证明CAP理论,以及CAP的权衡问题. CA ...
- postgresql sql查询结果添加序号列与每组第一个序号应用
1.postgresql 查询每组第一个 ROW_NUMBER () OVER (partition by 字段 ORDER BY 字段 DESC) 写法:SELECT ROW_NUMBER ( ...
- chrome 調試 node 代碼
(1)node --inspect-brk debug/demo (2)通过 chrome 进行调试 (3) chrome://inspect 进入chrome调试界面 --inspect ...
- CF480E Parking Lot(two-pointers + 单调队列优化)
题面 动态加障碍物,同时查询最大子正方形. n,m≤2000n,m\leq2000n,m≤2000 题解 加障碍不好做,直接离线后反着做,每次就是清除一个障碍物. 显然倒着做答案是递增的,而且答案的值 ...
- SpringAOP进阶
利用代理工厂实现增强 com.Spring.proxyfactory中的IdoSomeService package cn.spring.proxyfactory; public interface ...
- iwap问题
1. 2. . . ========================================================================================== ...
- [Luogu] 运输问题 -- 00
https://www.luogu.org/problemnew/show/4015 #include <bits/stdc++.h> #define gc getchar() using ...
- JSP+Oracle实现分页功能
Oracle: create table load( id char(200) not null, title varchar2(100) not null, time varchar2(100) n ...
- P1025 数的划分——简单题刷傻系列
P1025 数的划分 学傻了,学傻了,什么dp搜索什么啊: #include<cstdio> #include<cstring> #include<algorithm&g ...
- CF1174B Ehab Is an Odd Person(排序+结论)
做法 一个显然的结论就是如果至少有一个奇数和一个偶数,那么是可以随意调整的,也就是升序排序 否则不可以进行任何操作 Code #include<bits/stdc++.h> using n ...