Skip to content

Commit

Permalink
Merge pull request #14 from brandnetworks/customizable-to-label
Browse files Browse the repository at this point in the history
Add the ability to change to label text
  • Loading branch information
ayanonagon committed Aug 12, 2014
2 parents 2b3bee1 + 043be7e commit c481d4f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions VENTokenField/VENTokenField.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

@property (assign, nonatomic) UIKeyboardType inputTextFieldKeyboardType;
@property (strong, nonatomic) UIColor *toLabelTextColor;
@property (strong, nonatomic) NSString *toLabelText;
@property (strong, nonatomic) UIColor *inputTextFieldTextColor;

@property (strong, nonatomic) UILabel *toLabel;
Expand Down
23 changes: 21 additions & 2 deletions VENTokenField/VENTokenField.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ - (void)setUpInit
self.colorScheme = [UIColor blueColor];
self.toLabelTextColor = [UIColor colorWithRed:112/255.0f green:124/255.0f blue:124/255.0f alpha:1.0f];
self.inputTextFieldTextColor = [UIColor colorWithRed:38/255.0f green:39/255.0f blue:41/255.0f alpha:1.0f];

// Accessing bare value to avoid kicking off a premature layout run.
_toLabelText = NSLocalizedString(@"To:", nil);

self.originalHeight = CGRectGetHeight(self.frame);

Expand Down Expand Up @@ -161,6 +164,12 @@ - (void)setToLabelTextColor:(UIColor *)toLabelTextColor
self.toLabel.textColor = _toLabelTextColor;
}

- (void)setToLabelText:(NSString *)toLabelText
{
_toLabelText = toLabelText;
[self reloadData];
}

- (void)setColorScheme:(UIColor *)color
{
_colorScheme = color;
Expand Down Expand Up @@ -223,7 +232,15 @@ - (void)layoutToLabelInView:(UIView *)view origin:(CGPoint)origin currentX:(CGFl
{
[self.toLabel removeFromSuperview];
self.toLabel = [self toLabel];
self.toLabel.origin = origin;

CGRect newFrame = self.toLabel.frame;
newFrame.origin = origin;

[self.toLabel sizeToFit];
newFrame.size.width = CGRectGetWidth(self.toLabel.frame);

self.toLabel.frame = newFrame;

[view addSubview:self.toLabel];
*currentX += self.toLabel.hidden ? CGRectGetMinX(self.toLabel.frame) : CGRectGetMaxX(self.toLabel.frame) + VENTokenFieldDefaultToLabelPadding;
}
Expand Down Expand Up @@ -292,11 +309,13 @@ - (UILabel *)toLabel
_toLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_toLabel.textColor = self.toLabelTextColor;
_toLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:15.5];
_toLabel.text = NSLocalizedString(@"To:", nil);
_toLabel.x = 0;
[_toLabel sizeToFit];
[_toLabel setHeight:[self heightForToken]];
}
if (![_toLabel.text isEqualToString:_toLabelText]) {
_toLabel.text = _toLabelText;
}
return _toLabel;
}

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

0 comments on commit c481d4f

Please sign in to comment.