国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

【讀書筆記】UIWindow-密碼框

2019-11-14 18:37:28
字體:
來源:轉載
供稿:網友

一,工程結構,如下圖所示:

 

 

二,代碼

PassWordInputWindow.h

 

復制代碼
#import <UIKit/UIKit.h>@interface PasswordInputWindow : UIWindow+(PasswordInputWindow *)shareInstance;-(void)show;@end
復制代碼

 

PasswordInputWindow.m

 

復制代碼
#import "PasswordInputWindow.h"@implementation PasswordInputWindow{    UITextField *_textField;}+(PasswordInputWindow *)shareInstance{    static id shareInstance=nil;    static dispatch_once_t onceToken;    dispatch_once(&onceToken,^{                shareInstance=[[self alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    });    return shareInstance;}-(id)initWithFrame:(CGRect)frame{    self=[super initWithFrame:frame];    if (self) {                UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(10, 50, 200, 20)];        label.text=@"請輸入密碼";        [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:@"確定" 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)showErrorAlertView{    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:nil message:@"密碼錯誤,正確密碼是abcd" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];    [alertView show];}@end
復制代碼

 

三,運行效果。

 

 

 

參考資料 :

《iOS開發進階》-唐巧 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 勐海县| 桑日县| 丹江口市| 日喀则市| 仪征市| 上犹县| 基隆市| 新民市| 四平市| 竹北市| 库尔勒市| 安国市| 炉霍县| 沛县| 巴塘县| 西城区| 松滋市| 奎屯市| 霍山县| 修文县| 霍邱县| 河源市| 镇坪县| 枣强县| 徐汇区| 南昌市| 芦溪县| 清水河县| 兰西县| 盱眙县| 青冈县| 乳源| 平江县| 泰来县| 溧阳市| 牟定县| 澜沧| 兴国县| 天柱县| 马公市| 镇江市|