UIWindow-Password box, uiwindow-Password
1. project structure, as shown in:
Ii. Code
PasswordInputWindow. h
#import <UIKit/UIKit.h>@interface PasswordInputWindow : UIWindow+(PasswordInputWindow *)shareInstance;-(void)show;@end
PasswordInputWindow. m
# Import "PasswordInputWindow. h "@ implementation PasswordInputWindow {UITextField * _ textField;} + (PasswordInputWindow *) specify instance {static id reset instance = nil; static dispatch_once_t onceToken; dispatch_once (& onceToken, ^ {reset instance = [[self alloc] initWithFrame: [[UIScreen mainScreen] bounds] ;}); return reset instance ;}- (id) initWithFrame :( CGRect) frame {self = [super initWithFrame: frame]; if (self) {UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake (10, 50,200, 20)]; label. text = @ "enter the password"; [self addSubview: label]; UITextField * 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: @ "OK" forState: UIControlStateNormal]; [button addTarget: self action: @ selector (completeButtonPressed :) forControlEvents: UIControlEventTouchUpInside]; [self addSubview: button]; self. backgroundColor = [UIColor yellowColor]; _ textField = textField;} return self;}-(void) show {[self makeKeyAndVisible]; self. hidden = NO;}-(void) completeButtonPressed :( id) sender {if ([_ textField. text isEqualToString: @ "abcd"]) {[_ textField resignFirstResponder]; [self resignFirstResponder]; self. hidden = YES;} else {[self showErrorAlertView] ;}}- (void) Comment {UIAlertView * alertView = [[UIAlertView alloc] initWithTitle: nil message: @ "Incorrect password, the correct password is abcd "delegate: nil cancelButtonTitle: @" OK "otherButtonTitles: nil, nil]; [alertView show];} @ end
3. Running effect.
References:
Advanced iOS development-Tang Qiao