UITextField占位符具有不同的字体大小
我有几个在界面生成器中创build的textField,然后几个编程。 占位符文本似乎有不同的大小。 看来我应该能够获得相同的字体没有inheritanceUITextField。 我只是试图重新创build一个文本框,看起来像一个接口生成器。
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;
问题可能是,当你正在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,
PlaceHolder没有单独的字体function
你可以通过编程设置键值“@ 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]]; }
您可以set an attributed string on the placeholder
。 如果您的界面生成器文本字段正在使用属性string,则使用相同的属性,但前景色除外。
看到这个文档 :
他们从来没有不同的大小,这是UItextfield的textSize的大小。 请检查其属性的TextSize的大小