UIWindow-Password box, uiwindow-Password

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.