iOS 继承 UIWindow 的密码保护功能
2016-04-29 11:29
423 查看
- (void)applicationDidEnterBackground:(UIApplication *)application { [[PasswordInPutWindow shareHandle] show]; // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } #import "PasswordInPutWindow.h" @interface PasswordInPutWindow () @end @implementation PasswordInPutWindow { UITextField *_textField; } + (PasswordInPutWindow *)shareHandle{ static PasswordInPutWindow *passwordInPut = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ passwordInPut = [[PasswordInPutWindow alloc] init]; }); return passwordInPut; } - (instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 20, 200, 20)]; label.text = @"请输入密码"; label.textAlignment = NSTextAlignmentCenter; label.backgroundColor = [UIColor whiteColor]; [self addSubview:label]; _textField = [[UITextField alloc] initWithFrame:CGRectMake(50, 60, 200, 20)]; _textField.placeholder = @"请输入密码验证"; _textField.backgroundColor = [UIColor whiteColor]; [self addSubview:_textField]; UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)]; button.frame = CGRectMake(50, 100, 200, 20); button.backgroundColor = [UIColor whiteColor]; [button setTitle:@"确认" forState:(UIControlStateNormal)]; [button setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)]; [button addTarget:self action:@selector(buttonClick:) forControlEvents:(UIControlEventTouchUpInside)]; [self addSubview:button]; } return self; } - (void)buttonClick:(UIButton *)button{ if ([_textField.text isEqualToString:@"登陆时候的密码"]) { [self resignKeyWindow]; [self setHidden:YES]; } else { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"密码输入错误!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; alertView.backgroundColor = [UIColor whiteColor]; [alertView show]; } } - (void)show{ [self makeKeyWindow]; [self setHidden:NO]; }
相关文章推荐
- iOS 将UIImage裁剪成圆形
- UITextField中放置UIImage 和placeholder 字体、颜色、大小、位置
- Easyui Treegrid改变默认图标的方法
- iOS开发UI篇—无限轮播(循环利用)
- ESXi安装异常:VMware ESXi requires the Excute Disable/No Exceute CPU feature to be enabled
- Could not allocate CursorWindow size due to error -12 错误解决方法
- ShortGuid--简单便捷高效不区分大小写的短唯一ID
- Permutation Sequence
- 使用NSOperation以及NSOperationQueue
- POJ 2785 4 Values whose Sum is 0(排序+二分搜索)
- UILabel UIButton 混合问题 -iOS初学
- Android TextView实现滚动跑马灯效果Marquee
- /var/spool/clientmqueue目录~清理
- Easyui 之 Treegrid 笔记
- SoapUI命令行方式运行
- burpsuite
- Kendo UI常用示例汇总(七)
- iOS 键盘样式UIKeyboardType
- iOS 各种UI控件属性设置
- Build Instructions (Windows) – The Chromium Projects