Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextField placeholder text position wrong when right aligned and orientation changed

I'm not sure if I've found a bug or missing some intricate setting in the iOS SDK.

I have a UITextField with right aligned text and some placeholder text. I've set it to autosize when switching from portrait to landscape (IB settings are like this: http://db.tt/laTmXIS ).

When in Portrait, it all works as expected: http://db.tt/skf8wqN However, after rotating the placeholder text is in the wrong place: http://db.tt/7pU5kdR

It looks to me that the autoresizing properties are not replicated into the placeholder text UILabel subview.

I've replicated this in a new project (download here: http://db.tt/OSnvv2Y), so it's nothing funky in my code as far as I can see.

Any ideas?


Update: Dan's workaround fixes this. Add an IBOutlet connected to your textField and then add this code to your UIViewController...

- (void)didRotateFromInterfaceOrientation:
        (UIInterfaceOrientation)fromInterfaceOrientation {
    textField.textAlignment = UITextAlignmentLeft;
    textField.textAlignment = UITextAlignmentRight;
}
like image 460
Ian Kershaw Avatar asked Apr 20 '11 21:04

Ian Kershaw


2 Answers

i set it to left and then center in same function upon rotation, that seems to fix it until they fix the bug! :)

like image 85
dan Avatar answered Nov 17 '22 16:11

dan


This appears to be a bug in UIKit. Please file a bug report, including this sample project and images. It'd be nice if the sample app worked for both iPhone and iPad.

I agree that the text should stay flush with the right edge of the textfield.

like image 29
Dave DeLong Avatar answered Nov 17 '22 16:11

Dave DeLong