I'd like to change the color of the placeholder text I set in my UITextField
controls, to make it black.
I'd prefer to do this without using normal text as the placeholder and having to override all the methods to imitate the behaviour of a placeholder.
I believe if I override this method:
- (void)drawPlaceholderInRect:(CGRect)rect
then I should be able to do this. But I'm unsure how to access the actual placeholder object from within this method.
Categories FTW. Could be optimized to check for effective color change.
You can override
drawPlaceholderInRect:(CGRect)rect
as such to manually render the placeholder text:iOS 6 and later offers
attributedPlaceholder
onUITextField
. iOS 3.2 and later offerssetAttributes:range:
onNSMutableAttributedString
.You can do the following:
Maybe you want to try this way, but Apple might warn you about accessing private ivar:
NOTE
This is not working on iOS 7 anymore, according to Martin Alléus.
Easy and pain-free, could be an easy alternative for some.
Not suggested for production, Apple may reject your submission.
You can Change the Placeholder textcolor to any color which you want by using the below code.