-
Notifications
You must be signed in to change notification settings - Fork 195
/
ViewController.m
75 lines (59 loc) · 1.89 KB
/
ViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// ViewController.m
// VENTokenFieldSample
//
// Created by Ayaka Nonaka on 6/20/14.
// Copyright (c) 2014 Venmo. All rights reserved.
//
#import "ViewController.h"
#import "VENTokenField.h"
@interface ViewController () <VENTokenFieldDelegate, VENTokenFieldDataSource>
@property (weak, nonatomic) IBOutlet VENTokenField *tokenField;
@property (strong, nonatomic) NSMutableArray *names;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.names = [NSMutableArray array];
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.delimiters = @[@",", @";", @"--"];
[self.tokenField becomeFirstResponder];
}
- (IBAction)didTapCollapseButton:(id)sender
{
[self.tokenField collapse];
}
- (IBAction)didTapResignFirstResponderButton:(id)sender
{
[self.tokenField resignFirstResponder];
}
#pragma mark - VENTokenFieldDelegate
- (void)tokenField:(VENTokenField *)tokenField didEnterText:(NSString *)text
{
[self.names addObject:text];
[self.tokenField reloadData];
}
- (void)tokenField:(VENTokenField *)tokenField didDeleteTokenAtIndex:(NSUInteger)index
{
[self.names removeObjectAtIndex:index];
[self.tokenField reloadData];
}
#pragma mark - VENTokenFieldDataSource
- (NSString *)tokenField:(VENTokenField *)tokenField titleForTokenAtIndex:(NSUInteger)index
{
return self.names[index];
}
- (NSUInteger)numberOfTokensInTokenField:(VENTokenField *)tokenField
{
return [self.names count];
}
- (NSString *)tokenFieldCollapsedText:(VENTokenField *)tokenField
{
return [NSString stringWithFormat:@"%tu people", [self.names count]];
}
@end