-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathViewController.m
More file actions
138 lines (103 loc) · 4.38 KB
/
ViewController.m
File metadata and controls
138 lines (103 loc) · 4.38 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//
// ViewController.m
// PARTagPicker
//
// Created by Paul Rolfe on 7/21/15.
// Copyright (c) 2015 Paul Rolfe. All rights reserved.
//
#import "ViewController.h"
#import "PARTagPickerViewController.h"
#import "PARTagColorReference.h"
@interface ViewController () <PARTagPickerDelegate>
@property (nonatomic, strong) PARTagPickerViewController *tagPicker;
@property (nonatomic, strong) NSArray *allTags;
@property (nonatomic, strong) NSArray *preChosenTags;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initDummyData];
[self addTagPickerToView];
}
- (void)initDummyData {
//Data for demo project
self.allTags = @[@"one fish", @"two fish", @"red fish", @"blue fish", @"the cat in the hat", @"Seuss"];
self.preChosenTags = @[@"in a box", @"with a fox", @"thing 1", @"thing 2"];
}
- (void)addTagPickerToView {
self.tagPicker = [[PARTagPickerViewController alloc] init];
self.tagPicker.view.backgroundColor = [UIColor darkGrayColor];
self.tagPicker.view.frame = CGRectMake(0, 20, CGRectGetWidth(self.view.bounds), COLLECTION_VIEW_HEIGHT); //78 is the fully expanded height.
self.tagPicker.view.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.tagPicker.delegate = self;
self.tagPicker.allTags = self.allTags;
//optionally allow new tags to be made
//self.tagPicker.allowsNewTags = YES;
//optionally set some chosen tags
//self.tagPicker.chosenTags = [self.preChosenTags mutableCopy];
//optionally use custom colors using PARTagColorReference
//[self useCustomColors];
//optionally set the font for all the cells
//self.tagPicker.font = [UIFont fontWithName:@"Menlo-Regular" size:14];
//optionally set default placeholder text
//self.tagPicker.placeholderText = @"";
//optionally disable the tap to remove tags
//self.tagPicker.tapToEraseTags = NO;
//optionally disable all editing
//self.tagPicker.textfieldEnabled = NO;
//optionally take control of when the bottom row shows and hides, manually.
//self.tagPicker.shouldAutomaticallyChangeVisibilityState = NO;
[self addChildViewController:self.tagPicker];
[self.view addSubview:self.tagPicker.view];
}
- (void)useCustomColors {
PARTagColorReference *myColors = [PARTagColorReference new];
myColors.chosenTagBorderColor = [UIColor blueColor];
myColors.chosenTagBackgroundColor = [UIColor purpleColor];
myColors.chosenTagTextColor = [UIColor whiteColor];
myColors.defaultTagBorderColor = [UIColor greenColor];
myColors.defaultTagBackgroundColor = [UIColor orangeColor];
myColors.defaultTagTextColor = [UIColor blackColor];
myColors.highlightedTagBorderColor = [UIColor magentaColor];
myColors.highlightedTagBackgroundColor = [UIColor yellowColor];
myColors.highlightedTagTextColor = [UIColor blackColor];
self.tagPicker.tagColorRef = myColors;
}
#pragma mark - PARTagPickerDelegate
- (void)tagPicker:(PARTagPickerViewController *)tagPicker visibilityChangedToState:(PARTagPickerVisibilityState)state {
//you can adjust this view controller's view to change with the tagPicker's size change, if needed.
CGFloat newHeight = 0;
if (state == PARTagPickerVisibilityStateTopAndBottom) {
newHeight = 2 * COLLECTION_VIEW_HEIGHT;
} else if (state == PARTagPickerVisibilityStateTopOnly) {
newHeight = COLLECTION_VIEW_HEIGHT;
}
CGRect frame = self.tagPicker.view.frame;
frame.size.height = newHeight;
[UIView animateWithDuration:.5 animations:^{
self.tagPicker.view.frame = frame;
}];
}
- (void)chosenTagsWereUpdatedInTagPicker:(PARTagPickerViewController *)tagPicker {
//access chosen tags with tagPicker.chosenTags
}
- (void)searchStringDidChange:(NSString *)searchString {
//access chosen tags with searchString
}
#pragma mark - IBActions
- (IBAction)hideAllTags:(id)sender {
self.tagPicker.visibilityState = PARTagPickerVisibilityStateHidden;
}
- (IBAction)showAllTags:(id)sender {
self.tagPicker.visibilityState = PARTagPickerVisibilityStateTopAndBottom;
}
- (IBAction)showChosenTagsOnly:(id)sender {
self.tagPicker.visibilityState = PARTagPickerVisibilityStateTopOnly;
}
- (IBAction)addAll:(id)sender {
[_tagPicker setChosenTags:[self.allTags mutableCopy]];
}
- (IBAction)clearAll:(id)sender {
[_tagPicker setChosenTags:[@[] mutableCopy]];
}
@end