In the past, I haven’t paid attention to the placeholder. Recently, I found that the placeholder color is gone. After checking, I found that it is not the method that is invalid, but the position relationship:
[textField setValue:[UIColor orangeColor] forKeyPath:@"_placeholderLabel.textColor"]; TextField. Placeholder = @" Please input account name ";Copy the code
I write this is invalid, but the two lines of code position exchange is good, a big confusion, usually write when please tell me who noticed this problem? A lot of places don’t pay attention to order, do they? Hopefully, you’ve given this property when you write your code to set the color associated with this property, the font size, to prevent this from happening, and a way to set the placeholder color:
NSMutableDictionary *dict = [NSMutableDictionary dictionary]; Dict [NSForegroundColorAttributeName] = [UIColor colorWithRed: 0.95 f green: 0.95 f blue: f alpha 0.95:1.00 f]; NSAttributedString *attribute = [[NSAttributedString alloc] initWithString:@" Please enter account name "Attributes :dict]; [textField setAttributedPlaceholder:attribute];Copy the code