Change of UITextField placeholder color

后端 未结 13 1557
别跟我提以往
别跟我提以往 2021-01-30 06:09

How to dynamically change placeholder color of the UITextField? This is always the same system color.

No option in xib editor.

13条回答
  •  广开言路
    2021-01-30 07:04

    Easy and perfect solution.

    _placeholderLabel.textColor
    

    In swift

    myTextField.attributedPlaceholder = 
    NSAttributedString(string: "placeholder", attributes:[NSForegroundColorAttributeName : UIColor.redColor()])
    

    Objective-C

    UIColor *color = [UIColor grayColor];
    nameText.attributedPlaceholder =
       [[NSAttributedString alloc]
       initWithString:@"Full Name"
       attributes:@{NSForegroundColorAttributeName:color}];
    

    P.S Copied 3 different answers from Stackoverflow.

提交回复
热议问题