I have a strange problem. I have an UITextField in which the user should write the amount of something, so the field is called \"amountField\". Everything looks fine, when t
I had similar issues with a UITextfield
embedded in a UITableViewCell
. Where exactly is this code located in your project? What I believe is happening is that after you've finished editing a particular textfield, it sends itself -setNeedsDisplay
and its drawRect:
is subsequently called. This might explain the shift in alignment. In my particular scenario, I had to use a table view delegate method -willDisplayCell
... to set the content alignment. I would have to know more about your design to possibly offer a suggestion.
One potential solution would be to use the text field delegate methods to set the content alignment.
-(void)textFieldDidEndEditing:(UITextField *)textField{
if (amountField == textField){
amountField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
}
}