【发布时间】:2013-02-11 10:47:30
【问题描述】:
我正在使用子类UITextField 来使用自定义字体。当我为 textfield 设置占位符时,它会向上移动一点,但是当我开始输入文本时,文本的 frame 没有问题。有没有办法解决占位符移位问题。
【问题讨论】:
标签: iphone objective-c uitextfield subclass placeholder
我正在使用子类UITextField 来使用自定义字体。当我为 textfield 设置占位符时,它会向上移动一点,但是当我开始输入文本时,文本的 frame 没有问题。有没有办法解决占位符移位问题。
【问题讨论】:
标签: iphone objective-c uitextfield subclass placeholder
self.txtFirstName.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
self.txtFirstName.autocapitalizationType = UITextAutocapitalizationTypeSentences;
self.txtFirstName.placeholder = @"Enter First Name here";
self.txtFirstName.textAlignment = UITextAlignmentLeft;
【讨论】:
我遇到了同样的问题,我尝试了 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];
希望这会有所帮助。
【讨论】: