Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align text in UITextField?

Is it possible to align placeholder in the middle of a UITextField? And when we start editing it should it start from left corner of UITextField? I am new to iOS.

like image 890
varun Avatar asked Nov 05 '25 21:11

varun


1 Answers

Here is the sample code for that.

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    txtList.textAlignment = NSTextAlignmentCenter;
}
// This method is called once we click inside the textField
-(void)textFieldDidBeginEditing:(UITextField *)textField{

    txtList.textAlignment = NSTextAlignmentLeft;
}

Don't forgot to give delegate of UITextField.

like image 187
Nimit Parekh Avatar answered Nov 07 '25 15:11

Nimit Parekh