点击键盘的 next 按钮,在不同的 textField 之间换行

来源:互联网 发布:磁盘恢复软件免费版 编辑:程序博客网 时间:2024/06/07 03:32
首先给不同的textfield赋不同的且相邻的tag值
-(void)createTestTextField{    UITextField*tfOne = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 100, 20)];    tfOne.layer.cornerRadius = 5;    tfOne.tag = 0;    tfOne.delegate = self;    tfOne.backgroundColor = [UIColor redColor];    [self.view addSubview:tfOne];        CGFloat tfTwoY = CGRectGetMaxY(tfOne.frame)+20;    UITextField*tfTwo = [[UITextField alloc] initWithFrame:CGRectMake(100,tfTwoY , 100, 20)];    tfTwo.layer.cornerRadius = 5;    tfTwo.tag = 1;    tfTwo.delegate = self;    tfTwo.backgroundColor = [UIColor cyanColor];    [self.view addSubview:tfTwo];}-(BOOL)textFieldShouldReturn:(UITextField *)textField{    if ([textField returnKeyType] != UIReturnKeyDone) {        NSInteger nextTag = textField.tag+1;        UIView*nextTextField = [self.view viewWithTag:nextTag];        [nextTextField becomeFirstResponder];    }else{        [textField resignFirstResponder];    }    return YES;}

0 0
原创粉丝点击