Skip to content

Commit

Permalink
added placeholderFont property to both SurveyTextField and SurveyText…
Browse files Browse the repository at this point in the history
…View
  • Loading branch information
jlalvarez18 committed Jan 14, 2014
1 parent 81ca698 commit b5d89b7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
7 changes: 6 additions & 1 deletion Survey/SurveyTextField.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
*/
@property (copy, nonatomic) UIColor *placeholderColor;

/**
Allows for changing font of placeholder text.
*/
@property (copy, nonatomic) UIFont *placeholderFont;

/**
The next field in the form's list of fields
Expand All @@ -138,7 +143,7 @@
@return YES/NO if the field's value is valid.
*/
- (BOOL) isValid;
- (BOOL)isValid;


/**
Expand Down
8 changes: 5 additions & 3 deletions Survey/SurveyTextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,20 @@ - (void)moveToNextField
- (void)drawPlaceholderInRect:(CGRect)rect
{
_placeholderColor = _placeholderColor?:[UIColor colorWithWhite:0.7f alpha:1.0f];

_placeholderFont = _placeholderFont?:self.font;

if ([self.placeholder respondsToSelector:@selector(drawInRect:withAttributes:)]) {
// iOS 7 and later
NSDictionary *attributes = @{NSForegroundColorAttributeName: _placeholderColor, NSFontAttributeName: self.font};
NSDictionary *attributes = @{NSForegroundColorAttributeName: _placeholderColor, NSFontAttributeName: _placeholderFont};

[self.placeholder drawInRect:rect withAttributes:attributes];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// iOS 6
[_placeholderColor setFill];
[self.placeholder drawInRect:rect withFont:self.font lineBreakMode:NSLineBreakByTruncatingTail];

[self.placeholder drawInRect:rect withFont:_placeholderFont lineBreakMode:NSLineBreakByTruncatingTail];
#pragma clang diagnostic pop
}
}
Expand Down
5 changes: 5 additions & 0 deletions Survey/SurveyTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@
*/
@property (copy, nonatomic) UIColor *placeholderColor;

/**
Font for placeholder text.
*/
@property (copy, nonatomic) UIFont *placeholderFont;

/**
The next field in the form's list of fields
Expand Down
2 changes: 1 addition & 1 deletion Survey/SurveyTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ - (void)drawRect:(CGRect)rect
self.placeholderLabel = [[UILabel alloc] initWithFrame:CGRectMake(8,8,self.bounds.size.width - 16,0)];
self.placeholderLabel.lineBreakMode = NSLineBreakByWordWrapping;
self.placeholderLabel.numberOfLines = 0;
self.placeholderLabel.font = self.font;
self.placeholderLabel.font = self.placeholderFont?: self.font;
self.placeholderLabel.backgroundColor = [UIColor clearColor];
self.placeholderLabel.alpha = 0;

Expand Down

0 comments on commit b5d89b7

Please sign in to comment.