Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify color scheme to use tint color #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VENTokenField/VENToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

@property (assign, nonatomic) BOOL highlighted;
@property (copy, nonatomic) void (^didTapTokenBlock) (void);
@property (strong, nonatomic) UIColor *colorScheme;
@property (strong, nonatomic) UIColor *colorScheme DEPRECATED_ATTRIBUTE;

- (void)setTitleText:(NSString *)text;

Expand Down
23 changes: 15 additions & 8 deletions VENTokenField/VENToken.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ - (void)setUpInit
{
self.backgroundView.layer.cornerRadius = 5;
self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapToken:)];
self.colorScheme = [UIColor blueColor];
self.titleLabel.textColor = self.colorScheme;
self.titleLabel.textColor = self.tintColor;
[self addGestureRecognizer:self.tapGestureRecognizer];
}

- (void)setTitleText:(NSString *)text
{
self.titleLabel.text = text;
self.titleLabel.textColor = self.colorScheme;
self.titleLabel.textColor = self.tintColor;
[self.titleLabel sizeToFit];
self.frame = CGRectMake(CGRectGetMinX(self.frame), CGRectGetMinY(self.frame), CGRectGetMaxX(self.titleLabel.frame) + 3, CGRectGetHeight(self.frame));
[self.titleLabel sizeToFit];
Expand All @@ -60,19 +59,27 @@ - (void)setTitleText:(NSString *)text
- (void)setHighlighted:(BOOL)highlighted
{
_highlighted = highlighted;
UIColor *textColor = highlighted ? [UIColor whiteColor] : self.colorScheme;
UIColor *backgroundColor = highlighted ? self.colorScheme : [UIColor clearColor];
UIColor *textColor = highlighted ? [UIColor whiteColor] : self.tintColor;
UIColor *backgroundColor = highlighted ? self.tintColor : [UIColor clearColor];
self.titleLabel.textColor = textColor;
self.backgroundView.backgroundColor = backgroundColor;
}

- (void)setColorScheme:(UIColor *)colorScheme
- (void)tintColorDidChange
{
_colorScheme = colorScheme;
self.titleLabel.textColor = self.colorScheme;
self.titleLabel.textColor = self.tintColor;
[self setHighlighted:_highlighted];
}

// proxy color scheme out to tint color to avoid a major release.
- (UIColor *)colorScheme {
return self.tintColor;
}

- (void)setColorScheme:(UIColor *)colorScheme
{
self.tintColor = colorScheme;
}

#pragma mark - Private

Expand Down
2 changes: 1 addition & 1 deletion VENTokenField/VENTokenField.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

@property (copy, nonatomic) NSString *placeholderText;

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

@end

23 changes: 11 additions & 12 deletions VENTokenField/VENTokenField.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ @interface VENTokenField () <VENBackspaceTextFieldDelegate>
@property (strong, nonatomic) UITapGestureRecognizer *tapGestureRecognizer;
@property (strong, nonatomic) VENBackspaceTextField *invisibleTextField;
@property (strong, nonatomic) VENBackspaceTextField *inputTextField;
@property (strong, nonatomic) UIColor *colorScheme;
@property (strong, nonatomic) UILabel *collapsedLabel;

@end
Expand Down Expand Up @@ -84,7 +83,6 @@ - (void)setUpInit
self.horizontalInset = VENTokenFieldDefaultHorizontalInset;
self.tokenPadding = VENTokenFieldDefaultTokenPadding;
self.minInputWidth = VENTokenFieldDefaultMinInputWidth;
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];

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

- (void)tintColorDidChange
{
self.collapsedLabel.textColor = self.tintColor;
self.inputTextField.tintColor = self.tintColor;
}

- (void)setColorScheme:(UIColor *)color
{
_colorScheme = color;
self.collapsedLabel.textColor = color;
self.inputTextField.tintColor = color;
for (VENToken *token in self.tokens) {
[token setColorScheme:color];
}
self.tintColor = color;
}

- (NSString *)inputText
Expand Down Expand Up @@ -203,7 +202,7 @@ - (void)layoutInputTextFieldWithCurrentX:(CGFloat *)currentX currentY:(CGFloat *
VENBackspaceTextField *inputTextField = self.inputTextField;
inputTextField.text = @"";
inputTextField.frame = CGRectMake(*currentX, *currentY + 1, inputTextFieldWidth, [self heightForToken] - 1);
inputTextField.tintColor = self.colorScheme;
inputTextField.tintColor = self.tintColor;
[self.scrollView addSubview:inputTextField];
}

Expand All @@ -212,7 +211,7 @@ - (void)layoutCollapsedLabelWithCurrentX:(CGFloat *)currentX
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(*currentX, CGRectGetMinY(self.toLabel.frame), self.width - *currentX - self.horizontalInset, self.toLabel.height)];
label.font = [UIFont fontWithName:@"HelveticaNeue" size:15.5];
label.text = [self collapsedText];
label.textColor = self.colorScheme;
label.textColor = self.tintColor;
label.minimumScaleFactor = 5./label.font.pointSize;
label.adjustsFontSizeToFitWidth = YES;
[self addSubview:label];
Expand All @@ -233,7 +232,7 @@ - (void)layoutTokensWithCurrentX:(CGFloat *)currentX currentY:(CGFloat *)current
for (NSUInteger i = 0; i < [self numberOfTokens]; i++) {
NSString *title = [self titleForTokenAtIndex:i];
VENToken *token = [[VENToken alloc] init];
token.colorScheme = self.colorScheme;
token.tintColor = self.tintColor;

__weak VENToken *weakToken = token;
token.didTapTokenBlock = ^{
Expand Down Expand Up @@ -326,7 +325,7 @@ - (VENBackspaceTextField *)inputTextField
_inputTextField.font = [UIFont fontWithName:@"HelveticaNeue" size:15.5];
_inputTextField.accessibilityLabel = NSLocalizedString(@"To", nil);
_inputTextField.autocorrectionType = UITextAutocorrectionTypeNo;
_inputTextField.tintColor = self.colorScheme;
_inputTextField.tintColor = self.tintColor;
_inputTextField.delegate = self;
_inputTextField.placeholder = self.placeholderText;
[_inputTextField addTarget:self action:@selector(inputTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
Expand Down
2 changes: 1 addition & 1 deletion VENTokenFieldSample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ - (void)viewDidLoad
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]];
[self.tokenField setTintColor:[UIColor colorWithRed:61/255.0f green:149/255.0f blue:206/255.0f alpha:1.0f]];
[self.tokenField becomeFirstResponder];
}

Expand Down