码迷,mamicode.com
首页 > 移动开发 > 详细

ios登陆页以及键盘关闭demo

时间:2014-08-19 20:30:25      阅读:353      评论:0      收藏:0      [点我收藏+]

标签:os   io   for   ar   2014   cti   log   ad   

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

ios登陆页以及键盘关闭demo,布布扣,bubuko.com

ios登陆页以及键盘关闭demo

标签:os   io   for   ar   2014   cti   log   ad   

原文地址:http://www.cnblogs.com/decade/p/3922802.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!