Reputation:
i have 6 text field.i want to get current cursor position(cursor in which text field).like android onfocus .after i get the position i need to draw slider near to that textfield. is there any API for iPhone.guide me i'm new to iPhone and Xcode.
Upvotes: 0
Views: 917
Reputation: 643
If You want to see TextField In center OF Screen hen Use
Firstly You Add ScrollView in nid and connect and all TextField's delegete is connect with fileOwner
and Implement this code
It"s Better according to your View
#pragma mark -
#pragma mark textField Delegte
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
[self scrollViewToCenterOfScreen:textField];
return YES;
}
- (void)scrollViewToCenterOfScreen:(UIView *)theView {
CGFloat viewCenterY = theView.center.y;
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
CGFloat availableHeight = applicationFrame.size.height - 200; // Remove area covered by keyboard
CGFloat y = viewCenterY - availableHeight / 2.0;
if (y < 0) {
y = 0;
}
[scrollview setContentOffset:CGPointMake(0, y) animated:YES];
}
-(BOOL) textFieldShouldReturn:(UITextField *)textField{
if ([textField isEqual:textField1])
{
[textField2 becomeFirstResponder];
}
else if ([textField isEqual:textField2])
{
[textField3 becomeFirstResponder];
}
else if ([textField isEqual:textField3])
{
[textField4 becomeFirstResponder];
}
else
{
[textField4 resignFirstResponder];
[scrollview setContentOffset:CGPointMake(0, 0) animated:YES];
}
return YES;
}
Upvotes: 0
Reputation: 3515
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
}
Add your own logic for ‘for' loop here. I am using my logic. (As per my requirements).
NSArray *subviews = [[NSArray alloc] initWithArray:self.view.subviews];
for(UIView *subview in subviews)
if([subview isKindOfClass:[UITextField class]])
{
UITextField *textField = (UITextField *) subview;
if([textField isFirstResponder])
{
// do whatever you want
}
}
Upvotes: 1