I have 10 textfield in a UIView
, and I have added the view to a scrollView
. In that 5 textFields will be displayed, and other will be scrolled.
In my textFieldDidBeginEditing
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
if (textField.tag>=4)
{
CGRect viewframe=contentsOfView.frame;
viewframe.origin.y=viewframe.origin.y-100;
contentsOfView.frame=viewframe;
}
}
And in my textFieldDidEndEditing
-(void)textFieldDidEndEditing:(UITextField *)textField
{
if(textField.tag>=4)
{
CGRect viewframe=contentsOfView.frame;
viewframe.origin.y=viewframe.origin.y+100;
contentsOfView.frame=viewframe;
}
}
The first 5 fields which are getting displayed in the screen works perfectly, if I scroll the screen for the next text field. If I tap in it, the keyboard doesnt appears.
[contentsOfView addSubview:nameField];
[contentsOfView addSubview:mobileNumberField];
[contentsOfView addSubview:passwordField];
[contentsOfView addSubview:taxiNumberfield];
[contentsOfView addSubview:emailIdField];
[contentsOfView addSubview:taxiTypeField];
[contentsOfView addSubview:licenseNumber];
[contentsOfView addSubview:nricNumber];
[contentsOfView addSubview:noOfPassengerField];
[contentsOfScrollView addSubview:contentsOfView];
[self.view addSubView:contentScrollView ];
TextField
nameField.borderStyle=UITextBorderStyleLine;
nameField.layer.borderWidth=1.0;
nameField.layer.borderColor=[[HexColorCode colorWithHexastring:@"c88202" ] CGColor];
nameField.keyboardType=UIKeyboardTypeNamePhonePad;
nameField.placeholder=@"NAME";
nameField.backgroundColor=[UIColor whiteColor];
UIView * paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 20)];
nameField.leftView = paddingView;
nameField.leftViewMode = UITextFieldViewModeAlways;
nameField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
nameField.delegate=self;
nameField.tag=1;
Remove the contentView add the objects to the contectScrollView
[contentScrollView addSubView: nameField];
[self.View addSubView:contentScrollView];
This may help u.