我使用子类UITextField
来使用自定义字体。当我为textfield
设置占位符时,它会向上移动一点,但是当我开始输入文本时,frame
文本没有问题。有没有办法解决占位符转移问题。
答案 0 :(得分:1)
self.txtFirstName.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
self.txtFirstName.autocapitalizationType = UITextAutocapitalizationTypeSentences;
self.txtFirstName.placeholder = @"Enter First Name here";
self.txtFirstName.textAlignment = UITextAlignmentLeft;
答案 1 :(得分:0)
我有同样的问题,我尝试setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter
解决了我的问题。
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];
希望这有帮助。