From e6b69e5cdd28824b0feff8973126cd1d70347f87 Mon Sep 17 00:00:00 2001 From: Ayaka Nonaka Date: Tue, 8 Jul 2014 10:20:01 -0700 Subject: [PATCH] Allow setting placeholder text for input field --- VENTokenField/VENTokenField.h | 2 ++ VENTokenField/VENTokenField.m | 13 +++++++++++++ VENTokenFieldSample/ViewController.m | 1 + 3 files changed, 16 insertions(+) diff --git a/VENTokenField/VENTokenField.h b/VENTokenField/VENTokenField.h index dfe3c2e..eb25516 100644 --- a/VENTokenField/VENTokenField.h +++ b/VENTokenField/VENTokenField.h @@ -64,6 +64,8 @@ @property (strong, nonatomic) UILabel *toLabel; +@property (copy, nonatomic) NSString *placeholderText; + - (void)setColorScheme:(UIColor *)color; @end diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index ff0a146..20d680c 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -131,6 +131,7 @@ - (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:)]) { @@ -138,6 +139,12 @@ - (void)reloadData } } +- (void)setPlaceholderText:(NSString *)placeholderText +{ + _placeholderText = placeholderText; + self.inputTextField.placeholder = _placeholderText; +} + - (void)setColorScheme:(UIColor *)color { _colorScheme = color; @@ -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; @@ -339,6 +347,11 @@ - (void)setCursorVisibility } } +- (void)updateInputTextField +{ + self.inputTextField.placeholder = [self.tokens count] ? nil : self.placeholderText; +} + #pragma mark - Data Source diff --git a/VENTokenFieldSample/ViewController.m b/VENTokenFieldSample/ViewController.m index 76a0cf4..d10b1c1 100644 --- a/VENTokenFieldSample/ViewController.m +++ b/VENTokenFieldSample/ViewController.m @@ -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]]; }