diff --git a/SSToolkit/SSTextField.h b/SSToolkit/SSTextField.h index 8996fb1..224e520 100644 --- a/SSToolkit/SSTextField.h +++ b/SSToolkit/SSTextField.h @@ -15,6 +15,7 @@ UIEdgeInsets _textEdgeInsets; UIEdgeInsets _clearButtonEdgeInsets; + UIColor *_placeholderColor; } /** @@ -41,4 +42,12 @@ */ @property (nonatomic, assign) UIEdgeInsets clearButtonEdgeInsets; +/** + The color of the placeholder text. + + This property applies to the entire placeholder text string. The default value for this property is set by the system. + Setting this property to `nil` will use the system placeholder text color. + */ +@property (nonatomic, retain) UIColor *placeholderTextColor; + @end diff --git a/SSToolkit/SSTextField.m b/SSToolkit/SSTextField.m index aa24e86..653eb38 100644 --- a/SSToolkit/SSTextField.m +++ b/SSToolkit/SSTextField.m @@ -15,6 +15,25 @@ @implementation SSTextField @synthesize textEdgeInsets = _textEdgeInsets; @synthesize clearButtonEdgeInsets = _clearButtonEdgeInsets; +@synthesize placeholderTextColor = _placeholderTextColor; + +- (void)setPlaceholderTextColor:(UIColor *)placeholderTextColor { + [placeholderTextColor retain]; + [_placeholderTextColor release]; + _placeholderTextColor = placeholderTextColor; + + if (!self.text && self.placeholder) { + [self setNeedsDisplay]; + } +} + + +#pragma mark - NSObject + +- (void)dealloc { + [_placeholderTextColor release]; + [super dealloc]; +} #pragma mark - UIView @@ -46,4 +65,15 @@ - (CGRect)clearButtonRectForBounds:(CGRect)bounds { return CGRectSetX(rect, rect.origin.x + _clearButtonEdgeInsets.right); } + +- (void)drawPlaceholderInRect:(CGRect)rect { + if (!_placeholderTextColor) { + [super drawPlaceholderInRect:rect]; + return; + } + + [_placeholderTextColor setFill]; + [self.placeholder drawInRect:rect withFont:self.font lineBreakMode:UILineBreakModeTailTruncation alignment:self.textAlignment]; +} + @end