I have subclass the UITextField class and did the below code
- (void)drawPlaceholderInRect:(CGRect)rect
{
[self.placeHolderTextColor setFill];
[self.pl
The code bellow works on iOS 5/6/7
@implementation PlaceholderTextField
- (void)drawPlaceholderInRect:(CGRect)rect
{
// Placeholder text color, the same like default
UIColor *placeholderColor = [UIColor colorWithWhite:0.70 alpha:1];
[placeholderColor setFill];
// Get the size of placeholder text. We will use height to calculate frame Y position
CGSize size = [self.placeholder sizeWithFont:self.font];
// Vertically centered frame
CGRect placeholderRect = CGRectMake(rect.origin.x, (rect.size.height - size.height)/2, rect.size.width, size.height);
// Check if OS version is 7.0+ and draw placeholder a bit differently
if (IS_IOS7) {
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.lineBreakMode = NSLineBreakByTruncatingTail;
style.alignment = self.textAlignment;
NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys:style,NSParagraphStyleAttributeName, self.font, NSFontAttributeName, placeholderColor, NSForegroundColorAttributeName, nil];
[self.placeholder drawInRect:placeholderRect withAttributes:attr];
} else {
[self.placeholder drawInRect:placeholderRect
withFont:self.font
lineBreakMode:NSLineBreakByTruncatingTail
alignment:self.textAlignment];
}
}
@end