简体   繁体   中英

make UITextField placeholder text bold

i have set placeholder for UITextField in the Interface Builder. Now, how do i make the placeholder text bold.?

Please Use Following code for Your Problem.

    UIColor *color = [UIColor blackColor];
    UIFont* boldFont = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
    [self.textField setFont:boldFont];
    self.textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Test" attributes:@{NSForegroundColorAttributeName: color}];

May This help to lot.

The easiest way to do it is, If you change the property(font,size etc) of your UITextField it'll be applied to your placeholder as well. Just change the property of your UITextField and see the effect.

EDIT :

And then in your UITextField delegate method set this property to normal again.

- (void) drawPlaceholderInRect:(CGRect)rect {
    [[UIColor blackColor] setFill];
    [[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:14]];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM