ios开发,用户登录界面,输入用户名之后点击Next后切换到密码输入框,密码输入框输入后点击Return,键盘回收

来源:互联网 发布:数据库的二级映像结构 编辑:程序博客网 时间:2024/06/05 11:20

1.文本框定义,设置属性

//设置为属性或成员变量

UITextField *_userName;

UITextField *_passWd;


_userName=[[UITextFieldalloc]initWithFrame:CGRectMake(20,20,100,30)];

[_userNamesetBackgroundColor:[UIColorgrayColor]];

[_userName setReturnKeyType:UIReturnKeyNext];

[_userNamesetDelegate:self];

[self.viewaddSubview:_userName];



 _passWd=[[UITextFieldalloc]initWithFrame:CGRectMake(20,60,100,30)];

[_passWdsetBackgroundColor:[UIColorgrayColor]];

[_passWdsetDelegate:self];

[self.viewaddSubview:_passWd];

2.本类实现协议

 .h中添加

@interface ViewController :UIViewController<UITextFieldDelegate>

.m中实现

-(BOOL)textFieldShouldReturn:(UITextField *)textField

{

    if (textField==_userName) {

        [_passWdbecomeFirstResponder];  

    }

    else{

        [_passWdresignFirstResponder];

     }

   

return YES;

    }


  
0 0