How to set the color of the place holder text for a UITextField while preserving its existing properties?

前端 未结 5 949
没有蜡笔的小新
没有蜡笔的小新 2021-02-18 18:37

I have seen some answers that show how to change the placeHolder text color for UITextField by overriding the drawPlaceholderInRect: method such as this one:

iPhone UITe

5条回答
  •  逝去的感伤
    2021-02-18 18:54

    here See my outputThis is just for get system font name

    for (NSString *familyName in [UIFont familyNames]) {
         for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
             NSLog(@"%@", fontName);
    

    And add a this code in your viewDidLoad

    _textFieldEmail.attributedPlaceholder =
    [[NSAttributedString alloc] initWithString:@"e-mail address"
                                    attributes:@{
                                                 NSFontAttributeName : [UIFont fontWithName:@"Roboto-LightItalic" size:17.0]
                                                 }
     ];
    
    _textFieldPassword.attributedPlaceholder =
    [[NSAttributedString alloc] initWithString:@"password"
                                    attributes:@{
                                                 NSFontAttributeName : [UIFont fontWithName:@"Roboto-LightItalic" size:17.0]
                                                 }
     ];
    

提交回复
热议问题