Navigation Menu

Skip to content

Commit

Permalink
Add placeholderTextColor to SSTextField
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Sep 12, 2011
1 parent 8ceb82b commit a7d0c6a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions SSToolkit/SSTextField.h
Expand Up @@ -15,6 +15,7 @@

UIEdgeInsets _textEdgeInsets;
UIEdgeInsets _clearButtonEdgeInsets;
UIColor *_placeholderColor;
}

/**
Expand All @@ -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
30 changes: 30 additions & 0 deletions SSToolkit/SSTextField.m
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit a7d0c6a

Please sign in to comment.