2013-12-09 92 views
1

我在界面生成器中生成了幾個文本字段,然後編寫了一些文本字段。佔位符文本似乎有不同的大小。看來我應該能夠獲得相同的字體,而無需繼承UITextField。我只是試圖重新創建一個看起來像界面生成器的文本框。UITextField佔位符具有不同的字體大小

UITextField *textField = [[UITextField alloc] init]; 
textField.placeholder = string; 
[textField setTranslatesAutoresizingMaskIntoConstraints:NO]; 
[textField setBorderStyle:UITextBorderStyleRoundedRect]; 
[self.view addSubview:textField]; 
textField.returnKeyType = UIReturnKeyNext; 
textField.inputAccessoryView = [[QEDCKeyboardAccessory alloc] initWithDelegate:self]; 
textField.delegate = self; 
+0

那麼你的問題是什麼呢? –

+0

您可以在代碼中設置textfield fontsize。 – payal

+0

你可以發佈你用來創建textField的代碼嗎? –

回答

0

的問題可能是,當你即將creation of UITextField via programmatically and IB, The Font size of UItextfield are different

You just need to set the Font size are Equal by IB as well as Programmatically, 

有佔位符

沒有單獨的字體功能
+0

但是我們可以爲'textField'文本設置不同的字體,對吧? – aircraft

+0

@aircraft是的,你可以,,, textfield.textcolor *** .. –

0

它們從來沒有不同的大小,即UItextfield的textSize的大小。請檢查其屬性TextSize的大小

1

您可以set an attributed string on the placeholder。如果您的界面生成器文本字段正在使用屬性字符串,則它將使用相同的屬性,但前景色除外。

看到這個doc

+0

這是正確答案\ o/ – sachadso

2

您可以通過該鍵編程設定值做@ 「_ placeholderLabel.font」

[self.input setValue:[UIFont fontWithName: @"American Typewriter Bold" size: 20] forKeyPath:@"_placeholderLabel.font"]; 

和您也可以覆蓋drawPlaceholderInRect來執行此操作....

- (void) drawPlaceholderInRect:(CGRect)rect { 
     [[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:13]]; 
} 
+1

[self.txtField setValue:[UIFont fontWithName:@「HelveticaNeue-Light」size:14] forKeyPath:@「_ placeholderLabel.font」]; – GMJigar

相關問題