Search code examples
iosios7uitextfield

UITextField Alignment issue iOS 7


I am stuck in a very strange problem. A default text field in iOS 8 & 7 behave very strange. If the text box got focused the alignment of text get changed check the screen shots.

even with very small text size

enter image description here

enter image description here

Edit:

#import <UIKit/UIKit.h>

@interface LoginForm : UIViewController

@property (weak, nonatomic) IBOutlet UITextField *txt_username;
@property (weak, nonatomic) IBOutlet UITextField *txt_password;
- (IBAction)loginButtonPressed:(id)sender;

@end

Solution

  • Try this. Its more of a work around, not exactly getting to the root of the problem but make your VC a UITextFieldDelegate, then make it the textFields delegate and use the following code. -

    (void)textFieldDidBeginEditing:(UITextField *)textField
    {
        // Change the alignment if you need to.
        textField.textAlignment = NSTextAlignmentCenter;
    }