I am using a subclassed UITextField
to use a custom font. When I set a placeholder for that textfield
it gets shifted up a little, but the when I start entering the text, the frame
of text has no problem. Is there a way to fix the placeholder shifting issue.
Asked
Active
Viewed 632 times
0
-
1See these: http://stackoverflow.com/questions/1340224/iphone-uitextfield-change-placeholder-text-color & http://stackoverflow.com/questions/11539404/centering-placeholder-text-in-subclass-of-uitextfield – Vishal Feb 26 '13 at 04:37
2 Answers
1
self.txtFirstName.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
self.txtFirstName.autocapitalizationType = UITextAutocapitalizationTypeSentences;
self.txtFirstName.placeholder = @"Enter First Name here";
self.txtFirstName.textAlignment = UITextAlignmentLeft;

iPatel
- 46,010
- 16
- 115
- 137
0
I had same issue and I tried setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter
which solved my issue.
UITextField *txtPassword = [[UITextField alloc] initWithFrame:CGRectMake(15,55, 255, 25)];
[txtPassword setPlaceholder:@"Password..."];
[txtPassword setBackgroundColor:[UIColor whiteColor]];
[txtPassword setFont:[UIFont fontWithName:@"Helvetica" size:15]];
[txtPassword setSecureTextEntry:YES];
[txtPassword setTextAlignment:NSTextAlignmentCenter];
[txtPassword setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[txtPassword becomeFirstResponder];
Hope this helps.

βhargavḯ
- 9,786
- 1
- 37
- 59