Skip to content

Commit

Permalink
Allow setting placeholder text for input field
Browse files Browse the repository at this point in the history
  • Loading branch information
ayanonagon committed Jul 8, 2014
1 parent 4c59972 commit e6b69e5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions VENTokenField/VENTokenField.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@

@property (strong, nonatomic) UILabel *toLabel;

@property (copy, nonatomic) NSString *placeholderText;

- (void)setColorScheme:(UIColor *)color;

@end
Expand Down
13 changes: 13 additions & 0 deletions VENTokenField/VENTokenField.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,20 @@ - (void)reloadData
[self adjustHeightForCurrentY:currentY];
[self.scrollView setContentSize:CGSizeMake(self.scrollView.contentSize.width, currentY + [self heightForToken])];

[self updateInputTextField];
[self.inputTextField becomeFirstResponder];

if ([self.delegate respondsToSelector:@selector(tokenFieldDidBeginEditing:)]) {
[self.delegate tokenFieldDidBeginEditing:self];
}
}

- (void)setPlaceholderText:(NSString *)placeholderText
{
_placeholderText = placeholderText;
self.inputTextField.placeholder = _placeholderText;
}

- (void)setColorScheme:(UIColor *)color
{
_colorScheme = color;
Expand Down Expand Up @@ -289,6 +296,7 @@ - (VENBackspaceTextField *)inputTextField
_inputTextField.autocorrectionType = UITextAutocorrectionTypeNo;
_inputTextField.tintColor = self.colorScheme;
_inputTextField.delegate = self;
_inputTextField.placeholder = self.placeholderText;
[_inputTextField addTarget:self action:@selector(inputTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
}
return _inputTextField;
Expand Down Expand Up @@ -339,6 +347,11 @@ - (void)setCursorVisibility
}
}

- (void)updateInputTextField
{
self.inputTextField.placeholder = [self.tokens count] ? nil : self.placeholderText;
}


#pragma mark - Data Source

Expand Down
1 change: 1 addition & 0 deletions VENTokenFieldSample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ - (void)viewDidLoad
self.names = [NSMutableArray array];
self.tokenField.delegate = self;
self.tokenField.dataSource = self;
self.tokenField.placeholderText = NSLocalizedString(@"Enter names here", nil);
[self.tokenField setColorScheme:[UIColor colorWithRed:61/255.0f green:149/255.0f blue:206/255.0f alpha:1.0f]];
}

Expand Down

0 comments on commit e6b69e5

Please sign in to comment.