0
我使用子類型UITextField
來使用自定義字體。當我爲該textfield
設置一個佔位符時,它會稍微向上移動,但是當我開始輸入文本時,文本的frame
沒有問題。有沒有辦法解決佔位符轉移問題。UITextField佔位符在子類化時移位
我使用子類型UITextField
來使用自定義字體。當我爲該textfield
設置一個佔位符時,它會稍微向上移動,但是當我開始輸入文本時,文本的frame
沒有問題。有沒有辦法解決佔位符轉移問題。UITextField佔位符在子類化時移位
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];
希望這會有所幫助。
請參閱:http://stackoverflow.com/questions/1340224/iphone-uitextfield-change-placeholder-text-color&http://stackoverflow.com/questions/11539404/centering-placeholder-text-in-子類的-的UITextField – Vishal 2013-02-26 04:37:28