zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    ceph故障恢复
    上线遇到nginx问题
    java.lang.IllegalArgumentException: Comparison method violates its general contract 异常
    drone构建build时mvn日志太多,取消日志打印,输出失败异常
    mongo异常com.mongodb.MongoCursorNotFoundException
    循环list执行删除报ConcurrentModificationException异常
    磁盘目录/dev/vda2满了进行清理
    elasticSearch基本操作
    LOJ#6029「雅礼集训 2017 Day1」市场
    虚树
  • 原文地址:https://www.cnblogs.com/decade/p/3922802.html
Copyright © 2011-2022 走看看