Skip to content

Commit

Permalink
Merge pull request #103 from nsolter/PromptCustomization
Browse files Browse the repository at this point in the history
allow prompt color to be customized
  • Loading branch information
thermogl committed Jul 20, 2015
2 parents 0615c6e + 7c0124f commit 5a72d72
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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 @@ -879,17 +880,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 @@ -902,6 +904,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

0 comments on commit 5a72d72

Please sign in to comment.