ios登陆页以及键盘关闭demo


1、新建一个single view 的project

2、另外新建两个类(非必要) DElabel.h DETextField.h 将共用属性以及方法都放类当中,特殊属性以及方法直接放VC中

3、声明全局变量tfuser tfpass两个textfield

4、键盘关闭关键在新建一个背景,让背景触发事件让两个textfield失去控制权。

===========================

//

//  DEViewController.m

//  testLoginPage

//

//  Created by Decade on 14/8/18.

//  Copyright (c) 2014年 decade. All rights reserved.

//

 

#import "DEViewController.h"

 

@interface DEViewController ()

 

@end

 

@implementation DEViewController

 

- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

    

    

    UIControl *bglb = [[UIControl alloc]init];

    bglb.frame = [[UIScreen mainScreen]bounds];

    [bglb addTarget:self action:@selector(bgTap) forControlEvents:UIControlEventTouchDown];

    [self.view addSubview:bglb];

    

    DElabel *lbuser = [[DElabel alloc]init];

    lbuser.frame = CGRectMake(50, 80, 50, 30);

    lbuser.text = @"帐号:";

    [self.view addSubview:lbuser];

    

    DElabel *lbpass = [[DElabel alloc]init];

    lbpass.frame = CGRectMake(50, 120, 50, 30);

    lbpass.text = @"密码:";

    [self.view addSubview:lbpass];

    

    tfuser = [[DETextField alloc]init];

    tfuser.frame = CGRectMake(100, 80, 150, 30);

    tfuser.placeholder = @"请输入帐号";

//    [tfuser addTarget:self action:@selector(bgTap) forControlEvents:UIControlEventEditingDidEndOnExit];

    [self.view addSubview:tfuser];

    

    tfpass = [[DETextField alloc]init];

    tfpass.frame = CGRectMake(100, 120, 150, 30);

    tfpass.placeholder = @"请输入密码";

    tfpass.secureTextEntry = YES;

    tfpass.keyboardType = UIKeyboardTypeNumberPad;

    [self.view addSubview:tfpass];

 

}

 

 

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

//-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

//    if (![self.view isExclusiveTouch]) {

//        [self.view resignFirstResponder];

//    }

//}

-(void)bgTap{

    [tfuser resignFirstResponder];

    [tfpass resignFirstResponder];

}

 

@end

优质内容筛选与推荐>>
1、记第二次面试经历
2、序列化和反序列化
3、配置sql server 2000以允许远程访问
4、centos5.4系统,在vmware虚拟机中,配置本地yum源
5、文件大小计算


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号