Thursday, February 18, 2016

Objective C UITextField placeholder color

When we are customizing textfield color based on app theme color, we need to customize placeholder text color also.

Using bit of KVC (Key Value Coding) on textfield, we can access the placeholder label's text color key and can apply our own color as shown below.

[textField setValue:[UIColor blueColorforKeyPath:@"_placeholderLabel.textColor"];

Here, we are accessing textColor property of placeholder label directly using KVC.

We can also access placeholder directly like shown below.

UILabel *placeHolderLabel = [textField valueForKeyPath:@"_placeholderLabel"];

We can now customize this placeHolderLabel's font style, font size etc... 


Hope this post is useful. Feel free to comment in case of any queries.