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

allow prompt color to be customized #103

Merged
merged 2 commits into from
Jul 20, 2015
Merged
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
6 changes: 3 additions & 3 deletions TITokenField.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ typedef enum {
@property (nonatomic, readonly) int numberOfLines;
@property (nonatomic) int tokenLimit;
@property (nonatomic, strong) NSCharacterSet * tokenizingCharacters;
@property (strong, nonatomic) UIColor *promptColor;
// Pass nil to hide label
@property (strong, nonatomic) NSString *promptText;

- (void)addToken:(TIToken *)title;
- (TIToken *)addTokenWithTitle:(NSString *)title;
Expand All @@ -115,9 +118,6 @@ typedef enum {
- (void)layoutTokensAnimated:(BOOL)animated;
- (void)setResultsModeEnabled:(BOOL)enabled animated:(BOOL)animated;

// Pass nil to hide label
- (void)setPromptText:(NSString *)aText;

@end

//==========================================================
Expand Down
14 changes: 11 additions & 3 deletions TITokenField.m
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,8 @@ - (void)setup {
[self.layer setShadowRadius:12];

[self setPromptText:@"To:"];
[self setText:kTextEmpty];
[self setText:kTextEmpty];
self.promptColor = [UIColor colorWithWhite:0.5 alpha:1];

_internalDelegate = [[TITokenFieldInternalDelegate alloc] init];
[_internalDelegate setTokenField:self];
Expand Down Expand Up @@ -876,17 +877,18 @@ - (void)setResultsModeEnabled:(BOOL)flag animated:(BOOL)animated {
#pragma mark Left / Right view stuff
- (void)setPromptText:(NSString *)text {

_promptText = text;
if (text){

UILabel * label = (UILabel *)self.leftView;
if (!label || ![label isKindOfClass:[UILabel class]]){
label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setTextColor:[UIColor colorWithWhite:0.5 alpha:1]];
[self setLeftView:label];

[self setLeftViewMode:UITextFieldViewModeAlways];
}


[label setTextColor:_promptColor];
[label setText:text];
[label setFont:[UIFont systemFontOfSize:(self.font.pointSize + 1)]];
[label sizeToFit];
Expand All @@ -899,6 +901,12 @@ - (void)setPromptText:(NSString *)text {
[self layoutTokensAnimated:YES];
}

- (void)setPromptColor:(UIColor *)promptColor
{
_promptColor = promptColor;
[self setPromptText:_promptText];
}

- (void)setPlaceholder:(NSString *)placeholder {

if (placeholder){
Expand Down