Change of UITextField placeholder color

后端 未结 13 1740
别跟我提以往
别跟我提以往 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 06:51

    Try this:

    NSAttributedString *strUser = [[NSAttributedString alloc] initWithString:@"Username" attributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] }];
    NSAttributedString *strPassword = [[NSAttributedString alloc] initWithString:@"Password" attributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] }];
    
    self.username.attributedPlaceholder = strUser;
    self.password.attributedPlaceholder = strPassword;
    

提交回复
热议问题