├── .gitignore
├── LICENSE
├── README.md
├── RRTagController.xcodeproj
├── project.pbxproj
└── project.xcworkspace
│ └── contents.xcworkspacedata
├── RRTagController
├── AppDelegate.swift
├── Base.lproj
│ ├── LaunchScreen.xib
│ └── Main.storyboard
├── Images.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── Info.plist
├── RRAddTagView.swift
├── RRTagCollectionViewCell.swift
├── RRTagController.swift
└── ViewController.swift
├── RRTagControllerTests
├── Info.plist
└── RRTagControllerTests.swift
└── source
├── RRAddTagView.swift
├── RRTagCollectionViewCell.swift
├── RRTagController.swift
├── anim.gif
└── banner.png
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | build/
4 | *.pbxuser
5 | !default.pbxuser
6 | *.mode1v3
7 | !default.mode1v3
8 | *.mode2v3
9 | !default.mode2v3
10 | *.perspectivev3
11 | !default.perspectivev3
12 | xcuserdata
13 | *.xccheckout
14 | *.moved-aside
15 | DerivedData
16 | *.hmap
17 | *.ipa
18 | *.xcuserstate
19 |
20 | # CocoaPods
21 | #
22 | # We recommend against adding the Pods directory to your .gitignore. However
23 | # you should judge for yourself, the pros and cons are mentioned at:
24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
25 | #
26 | # Pods/
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 rémi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Allows the user to make a choice among predefined tags. It should also be the opportunity to create new ones. It can cancel or, validate if at least one choice was made.
8 | RRTagController is a subClass of an UIViewController. It's very easy to customize.
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | Usage
17 | only one line of code enough to use it :
18 | ```Swift
19 | let tag = ["Albanie", "Allemagne", "Andorre", "Autriche-Hongrie", "Belgique", "Bulgarie", "Danemark", "Espagne", "France", "Grèce", "Italie", "Liechtenstein", "Luxembourg", "Monaco", "Monténégro", "Norvège", "Pays-Bas", "Portugal", "Roumanie", "Royaume-Uni", "Russie", "Saint-Marin", "Serbie", "Suède", "Suisse"]
20 |
21 | RRTagController.displayTagController(parentController: self, tagsString: tag,
22 | blockFinish: { (selectedTags, unSelectedTags) -> () in
23 | // the user finished the selection and returns the separated list Selected and not selected.
24 | }) { () -> () in
25 | // here the user cancel the selection, nothing is returned.
26 | }
27 | ```
28 |
--------------------------------------------------------------------------------
/RRTagController.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | BB8A0A751A97804700E278A0 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8A0A741A97804700E278A0 /* AppDelegate.swift */; };
11 | BB8A0A771A97804700E278A0 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8A0A761A97804700E278A0 /* ViewController.swift */; };
12 | BB8A0A7A1A97804700E278A0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BB8A0A781A97804700E278A0 /* Main.storyboard */; };
13 | BB8A0A7C1A97804700E278A0 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BB8A0A7B1A97804700E278A0 /* Images.xcassets */; };
14 | BB8A0A7F1A97804700E278A0 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB8A0A7D1A97804700E278A0 /* LaunchScreen.xib */; };
15 | BB8A0A8B1A97804700E278A0 /* RRTagControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8A0A8A1A97804700E278A0 /* RRTagControllerTests.swift */; };
16 | BB8A0A951A97806300E278A0 /* RRTagController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8A0A941A97806300E278A0 /* RRTagController.swift */; };
17 | BB8A0A971A9785DE00E278A0 /* RRTagCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8A0A961A9785DE00E278A0 /* RRTagCollectionViewCell.swift */; };
18 | BB8A0A991A97E99C00E278A0 /* RRAddTagView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8A0A981A97E99C00E278A0 /* RRAddTagView.swift */; };
19 | /* End PBXBuildFile section */
20 |
21 | /* Begin PBXContainerItemProxy section */
22 | BB8A0A851A97804700E278A0 /* PBXContainerItemProxy */ = {
23 | isa = PBXContainerItemProxy;
24 | containerPortal = BB8A0A671A97804600E278A0 /* Project object */;
25 | proxyType = 1;
26 | remoteGlobalIDString = BB8A0A6E1A97804600E278A0;
27 | remoteInfo = RRTagController;
28 | };
29 | /* End PBXContainerItemProxy section */
30 |
31 | /* Begin PBXFileReference section */
32 | BB8A0A6F1A97804700E278A0 /* RRTagController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RRTagController.app; sourceTree = BUILT_PRODUCTS_DIR; };
33 | BB8A0A731A97804700E278A0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
34 | BB8A0A741A97804700E278A0 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
35 | BB8A0A761A97804700E278A0 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
36 | BB8A0A791A97804700E278A0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
37 | BB8A0A7B1A97804700E278A0 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; };
38 | BB8A0A7E1A97804700E278A0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; };
39 | BB8A0A841A97804700E278A0 /* RRTagControllerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RRTagControllerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
40 | BB8A0A891A97804700E278A0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
41 | BB8A0A8A1A97804700E278A0 /* RRTagControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RRTagControllerTests.swift; sourceTree = ""; };
42 | BB8A0A941A97806300E278A0 /* RRTagController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RRTagController.swift; sourceTree = ""; };
43 | BB8A0A961A9785DE00E278A0 /* RRTagCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RRTagCollectionViewCell.swift; sourceTree = ""; };
44 | BB8A0A981A97E99C00E278A0 /* RRAddTagView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RRAddTagView.swift; sourceTree = ""; };
45 | /* End PBXFileReference section */
46 |
47 | /* Begin PBXFrameworksBuildPhase section */
48 | BB8A0A6C1A97804600E278A0 /* Frameworks */ = {
49 | isa = PBXFrameworksBuildPhase;
50 | buildActionMask = 2147483647;
51 | files = (
52 | );
53 | runOnlyForDeploymentPostprocessing = 0;
54 | };
55 | BB8A0A811A97804700E278A0 /* Frameworks */ = {
56 | isa = PBXFrameworksBuildPhase;
57 | buildActionMask = 2147483647;
58 | files = (
59 | );
60 | runOnlyForDeploymentPostprocessing = 0;
61 | };
62 | /* End PBXFrameworksBuildPhase section */
63 |
64 | /* Begin PBXGroup section */
65 | BB8A0A661A97804600E278A0 = {
66 | isa = PBXGroup;
67 | children = (
68 | BB8A0A711A97804700E278A0 /* RRTagController */,
69 | BB8A0A871A97804700E278A0 /* RRTagControllerTests */,
70 | BB8A0A701A97804700E278A0 /* Products */,
71 | );
72 | sourceTree = "";
73 | };
74 | BB8A0A701A97804700E278A0 /* Products */ = {
75 | isa = PBXGroup;
76 | children = (
77 | BB8A0A6F1A97804700E278A0 /* RRTagController.app */,
78 | BB8A0A841A97804700E278A0 /* RRTagControllerTests.xctest */,
79 | );
80 | name = Products;
81 | sourceTree = "";
82 | };
83 | BB8A0A711A97804700E278A0 /* RRTagController */ = {
84 | isa = PBXGroup;
85 | children = (
86 | BB8A0A741A97804700E278A0 /* AppDelegate.swift */,
87 | BB8A0A761A97804700E278A0 /* ViewController.swift */,
88 | BB8A0A941A97806300E278A0 /* RRTagController.swift */,
89 | BB8A0A981A97E99C00E278A0 /* RRAddTagView.swift */,
90 | BB8A0A961A9785DE00E278A0 /* RRTagCollectionViewCell.swift */,
91 | BB8A0A781A97804700E278A0 /* Main.storyboard */,
92 | BB8A0A7B1A97804700E278A0 /* Images.xcassets */,
93 | BB8A0A7D1A97804700E278A0 /* LaunchScreen.xib */,
94 | BB8A0A721A97804700E278A0 /* Supporting Files */,
95 | );
96 | path = RRTagController;
97 | sourceTree = "";
98 | };
99 | BB8A0A721A97804700E278A0 /* Supporting Files */ = {
100 | isa = PBXGroup;
101 | children = (
102 | BB8A0A731A97804700E278A0 /* Info.plist */,
103 | );
104 | name = "Supporting Files";
105 | sourceTree = "";
106 | };
107 | BB8A0A871A97804700E278A0 /* RRTagControllerTests */ = {
108 | isa = PBXGroup;
109 | children = (
110 | BB8A0A8A1A97804700E278A0 /* RRTagControllerTests.swift */,
111 | BB8A0A881A97804700E278A0 /* Supporting Files */,
112 | );
113 | path = RRTagControllerTests;
114 | sourceTree = "";
115 | };
116 | BB8A0A881A97804700E278A0 /* Supporting Files */ = {
117 | isa = PBXGroup;
118 | children = (
119 | BB8A0A891A97804700E278A0 /* Info.plist */,
120 | );
121 | name = "Supporting Files";
122 | sourceTree = "";
123 | };
124 | /* End PBXGroup section */
125 |
126 | /* Begin PBXNativeTarget section */
127 | BB8A0A6E1A97804600E278A0 /* RRTagController */ = {
128 | isa = PBXNativeTarget;
129 | buildConfigurationList = BB8A0A8E1A97804700E278A0 /* Build configuration list for PBXNativeTarget "RRTagController" */;
130 | buildPhases = (
131 | BB8A0A6B1A97804600E278A0 /* Sources */,
132 | BB8A0A6C1A97804600E278A0 /* Frameworks */,
133 | BB8A0A6D1A97804600E278A0 /* Resources */,
134 | );
135 | buildRules = (
136 | );
137 | dependencies = (
138 | );
139 | name = RRTagController;
140 | productName = RRTagController;
141 | productReference = BB8A0A6F1A97804700E278A0 /* RRTagController.app */;
142 | productType = "com.apple.product-type.application";
143 | };
144 | BB8A0A831A97804700E278A0 /* RRTagControllerTests */ = {
145 | isa = PBXNativeTarget;
146 | buildConfigurationList = BB8A0A911A97804700E278A0 /* Build configuration list for PBXNativeTarget "RRTagControllerTests" */;
147 | buildPhases = (
148 | BB8A0A801A97804700E278A0 /* Sources */,
149 | BB8A0A811A97804700E278A0 /* Frameworks */,
150 | BB8A0A821A97804700E278A0 /* Resources */,
151 | );
152 | buildRules = (
153 | );
154 | dependencies = (
155 | BB8A0A861A97804700E278A0 /* PBXTargetDependency */,
156 | );
157 | name = RRTagControllerTests;
158 | productName = RRTagControllerTests;
159 | productReference = BB8A0A841A97804700E278A0 /* RRTagControllerTests.xctest */;
160 | productType = "com.apple.product-type.bundle.unit-test";
161 | };
162 | /* End PBXNativeTarget section */
163 |
164 | /* Begin PBXProject section */
165 | BB8A0A671A97804600E278A0 /* Project object */ = {
166 | isa = PBXProject;
167 | attributes = {
168 | LastUpgradeCheck = 0610;
169 | ORGANIZATIONNAME = "Remi Robert";
170 | TargetAttributes = {
171 | BB8A0A6E1A97804600E278A0 = {
172 | CreatedOnToolsVersion = 6.1.1;
173 | };
174 | BB8A0A831A97804700E278A0 = {
175 | CreatedOnToolsVersion = 6.1.1;
176 | TestTargetID = BB8A0A6E1A97804600E278A0;
177 | };
178 | };
179 | };
180 | buildConfigurationList = BB8A0A6A1A97804600E278A0 /* Build configuration list for PBXProject "RRTagController" */;
181 | compatibilityVersion = "Xcode 3.2";
182 | developmentRegion = English;
183 | hasScannedForEncodings = 0;
184 | knownRegions = (
185 | en,
186 | Base,
187 | );
188 | mainGroup = BB8A0A661A97804600E278A0;
189 | productRefGroup = BB8A0A701A97804700E278A0 /* Products */;
190 | projectDirPath = "";
191 | projectRoot = "";
192 | targets = (
193 | BB8A0A6E1A97804600E278A0 /* RRTagController */,
194 | BB8A0A831A97804700E278A0 /* RRTagControllerTests */,
195 | );
196 | };
197 | /* End PBXProject section */
198 |
199 | /* Begin PBXResourcesBuildPhase section */
200 | BB8A0A6D1A97804600E278A0 /* Resources */ = {
201 | isa = PBXResourcesBuildPhase;
202 | buildActionMask = 2147483647;
203 | files = (
204 | BB8A0A7A1A97804700E278A0 /* Main.storyboard in Resources */,
205 | BB8A0A7F1A97804700E278A0 /* LaunchScreen.xib in Resources */,
206 | BB8A0A7C1A97804700E278A0 /* Images.xcassets in Resources */,
207 | );
208 | runOnlyForDeploymentPostprocessing = 0;
209 | };
210 | BB8A0A821A97804700E278A0 /* Resources */ = {
211 | isa = PBXResourcesBuildPhase;
212 | buildActionMask = 2147483647;
213 | files = (
214 | );
215 | runOnlyForDeploymentPostprocessing = 0;
216 | };
217 | /* End PBXResourcesBuildPhase section */
218 |
219 | /* Begin PBXSourcesBuildPhase section */
220 | BB8A0A6B1A97804600E278A0 /* Sources */ = {
221 | isa = PBXSourcesBuildPhase;
222 | buildActionMask = 2147483647;
223 | files = (
224 | BB8A0A771A97804700E278A0 /* ViewController.swift in Sources */,
225 | BB8A0A951A97806300E278A0 /* RRTagController.swift in Sources */,
226 | BB8A0A991A97E99C00E278A0 /* RRAddTagView.swift in Sources */,
227 | BB8A0A751A97804700E278A0 /* AppDelegate.swift in Sources */,
228 | BB8A0A971A9785DE00E278A0 /* RRTagCollectionViewCell.swift in Sources */,
229 | );
230 | runOnlyForDeploymentPostprocessing = 0;
231 | };
232 | BB8A0A801A97804700E278A0 /* Sources */ = {
233 | isa = PBXSourcesBuildPhase;
234 | buildActionMask = 2147483647;
235 | files = (
236 | BB8A0A8B1A97804700E278A0 /* RRTagControllerTests.swift in Sources */,
237 | );
238 | runOnlyForDeploymentPostprocessing = 0;
239 | };
240 | /* End PBXSourcesBuildPhase section */
241 |
242 | /* Begin PBXTargetDependency section */
243 | BB8A0A861A97804700E278A0 /* PBXTargetDependency */ = {
244 | isa = PBXTargetDependency;
245 | target = BB8A0A6E1A97804600E278A0 /* RRTagController */;
246 | targetProxy = BB8A0A851A97804700E278A0 /* PBXContainerItemProxy */;
247 | };
248 | /* End PBXTargetDependency section */
249 |
250 | /* Begin PBXVariantGroup section */
251 | BB8A0A781A97804700E278A0 /* Main.storyboard */ = {
252 | isa = PBXVariantGroup;
253 | children = (
254 | BB8A0A791A97804700E278A0 /* Base */,
255 | );
256 | name = Main.storyboard;
257 | sourceTree = "";
258 | };
259 | BB8A0A7D1A97804700E278A0 /* LaunchScreen.xib */ = {
260 | isa = PBXVariantGroup;
261 | children = (
262 | BB8A0A7E1A97804700E278A0 /* Base */,
263 | );
264 | name = LaunchScreen.xib;
265 | sourceTree = "";
266 | };
267 | /* End PBXVariantGroup section */
268 |
269 | /* Begin XCBuildConfiguration section */
270 | BB8A0A8C1A97804700E278A0 /* Debug */ = {
271 | isa = XCBuildConfiguration;
272 | buildSettings = {
273 | ALWAYS_SEARCH_USER_PATHS = NO;
274 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
275 | CLANG_CXX_LIBRARY = "libc++";
276 | CLANG_ENABLE_MODULES = YES;
277 | CLANG_ENABLE_OBJC_ARC = YES;
278 | CLANG_WARN_BOOL_CONVERSION = YES;
279 | CLANG_WARN_CONSTANT_CONVERSION = YES;
280 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
281 | CLANG_WARN_EMPTY_BODY = YES;
282 | CLANG_WARN_ENUM_CONVERSION = YES;
283 | CLANG_WARN_INT_CONVERSION = YES;
284 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
285 | CLANG_WARN_UNREACHABLE_CODE = YES;
286 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
287 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
288 | COPY_PHASE_STRIP = NO;
289 | ENABLE_STRICT_OBJC_MSGSEND = YES;
290 | GCC_C_LANGUAGE_STANDARD = gnu99;
291 | GCC_DYNAMIC_NO_PIC = NO;
292 | GCC_OPTIMIZATION_LEVEL = 0;
293 | GCC_PREPROCESSOR_DEFINITIONS = (
294 | "DEBUG=1",
295 | "$(inherited)",
296 | );
297 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
298 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
299 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
300 | GCC_WARN_UNDECLARED_SELECTOR = YES;
301 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
302 | GCC_WARN_UNUSED_FUNCTION = YES;
303 | GCC_WARN_UNUSED_VARIABLE = YES;
304 | IPHONEOS_DEPLOYMENT_TARGET = 8.1;
305 | MTL_ENABLE_DEBUG_INFO = YES;
306 | ONLY_ACTIVE_ARCH = YES;
307 | SDKROOT = iphoneos;
308 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
309 | };
310 | name = Debug;
311 | };
312 | BB8A0A8D1A97804700E278A0 /* Release */ = {
313 | isa = XCBuildConfiguration;
314 | buildSettings = {
315 | ALWAYS_SEARCH_USER_PATHS = NO;
316 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
317 | CLANG_CXX_LIBRARY = "libc++";
318 | CLANG_ENABLE_MODULES = YES;
319 | CLANG_ENABLE_OBJC_ARC = YES;
320 | CLANG_WARN_BOOL_CONVERSION = YES;
321 | CLANG_WARN_CONSTANT_CONVERSION = YES;
322 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
323 | CLANG_WARN_EMPTY_BODY = YES;
324 | CLANG_WARN_ENUM_CONVERSION = YES;
325 | CLANG_WARN_INT_CONVERSION = YES;
326 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
327 | CLANG_WARN_UNREACHABLE_CODE = YES;
328 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
329 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
330 | COPY_PHASE_STRIP = YES;
331 | ENABLE_NS_ASSERTIONS = NO;
332 | ENABLE_STRICT_OBJC_MSGSEND = YES;
333 | GCC_C_LANGUAGE_STANDARD = gnu99;
334 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
335 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
336 | GCC_WARN_UNDECLARED_SELECTOR = YES;
337 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
338 | GCC_WARN_UNUSED_FUNCTION = YES;
339 | GCC_WARN_UNUSED_VARIABLE = YES;
340 | IPHONEOS_DEPLOYMENT_TARGET = 8.1;
341 | MTL_ENABLE_DEBUG_INFO = NO;
342 | SDKROOT = iphoneos;
343 | VALIDATE_PRODUCT = YES;
344 | };
345 | name = Release;
346 | };
347 | BB8A0A8F1A97804700E278A0 /* Debug */ = {
348 | isa = XCBuildConfiguration;
349 | buildSettings = {
350 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
351 | INFOPLIST_FILE = RRTagController/Info.plist;
352 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
353 | PRODUCT_NAME = "$(TARGET_NAME)";
354 | };
355 | name = Debug;
356 | };
357 | BB8A0A901A97804700E278A0 /* Release */ = {
358 | isa = XCBuildConfiguration;
359 | buildSettings = {
360 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
361 | INFOPLIST_FILE = RRTagController/Info.plist;
362 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
363 | PRODUCT_NAME = "$(TARGET_NAME)";
364 | };
365 | name = Release;
366 | };
367 | BB8A0A921A97804700E278A0 /* Debug */ = {
368 | isa = XCBuildConfiguration;
369 | buildSettings = {
370 | BUNDLE_LOADER = "$(TEST_HOST)";
371 | FRAMEWORK_SEARCH_PATHS = (
372 | "$(SDKROOT)/Developer/Library/Frameworks",
373 | "$(inherited)",
374 | );
375 | GCC_PREPROCESSOR_DEFINITIONS = (
376 | "DEBUG=1",
377 | "$(inherited)",
378 | );
379 | INFOPLIST_FILE = RRTagControllerTests/Info.plist;
380 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
381 | PRODUCT_NAME = "$(TARGET_NAME)";
382 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RRTagController.app/RRTagController";
383 | };
384 | name = Debug;
385 | };
386 | BB8A0A931A97804700E278A0 /* Release */ = {
387 | isa = XCBuildConfiguration;
388 | buildSettings = {
389 | BUNDLE_LOADER = "$(TEST_HOST)";
390 | FRAMEWORK_SEARCH_PATHS = (
391 | "$(SDKROOT)/Developer/Library/Frameworks",
392 | "$(inherited)",
393 | );
394 | INFOPLIST_FILE = RRTagControllerTests/Info.plist;
395 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
396 | PRODUCT_NAME = "$(TARGET_NAME)";
397 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RRTagController.app/RRTagController";
398 | };
399 | name = Release;
400 | };
401 | /* End XCBuildConfiguration section */
402 |
403 | /* Begin XCConfigurationList section */
404 | BB8A0A6A1A97804600E278A0 /* Build configuration list for PBXProject "RRTagController" */ = {
405 | isa = XCConfigurationList;
406 | buildConfigurations = (
407 | BB8A0A8C1A97804700E278A0 /* Debug */,
408 | BB8A0A8D1A97804700E278A0 /* Release */,
409 | );
410 | defaultConfigurationIsVisible = 0;
411 | defaultConfigurationName = Release;
412 | };
413 | BB8A0A8E1A97804700E278A0 /* Build configuration list for PBXNativeTarget "RRTagController" */ = {
414 | isa = XCConfigurationList;
415 | buildConfigurations = (
416 | BB8A0A8F1A97804700E278A0 /* Debug */,
417 | BB8A0A901A97804700E278A0 /* Release */,
418 | );
419 | defaultConfigurationIsVisible = 0;
420 | };
421 | BB8A0A911A97804700E278A0 /* Build configuration list for PBXNativeTarget "RRTagControllerTests" */ = {
422 | isa = XCConfigurationList;
423 | buildConfigurations = (
424 | BB8A0A921A97804700E278A0 /* Debug */,
425 | BB8A0A931A97804700E278A0 /* Release */,
426 | );
427 | defaultConfigurationIsVisible = 0;
428 | };
429 | /* End XCConfigurationList section */
430 | };
431 | rootObject = BB8A0A671A97804600E278A0 /* Project object */;
432 | }
433 |
--------------------------------------------------------------------------------
/RRTagController.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/RRTagController/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // RRTagController
4 | //
5 | // Created by Remi Robert on 20/02/15.
6 | // Copyright (c) 2015 Remi Robert. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(application: UIApplication) {
33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/RRTagController/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/RRTagController/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/RRTagController/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | }
33 | ],
34 | "info" : {
35 | "version" : 1,
36 | "author" : "xcode"
37 | }
38 | }
--------------------------------------------------------------------------------
/RRTagController/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | com.remirobert.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/RRTagController/RRAddTagView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // RRAddTagView.swift
3 | // RRTagController
4 | //
5 | // Created by Remi Robert on 20/02/15.
6 | // Copyright (c) 2015 Remi Robert. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class RRAddTagView: UIView, UITextViewDelegate {
12 |
13 | lazy var title: UILabel = {
14 | let title = UILabel(frame: CGRectMake(10, 10, UIScreen.mainScreen().bounds.size.width - 20, 20))
15 | title.font = UIFont.boldSystemFontOfSize(18)
16 | title.textAlignment = NSTextAlignment.Center
17 | return title
18 | }()
19 |
20 | lazy var textEdit: UITextView = {
21 | let textEdit = UITextView(frame: CGRectMake(10, 30, UIScreen.mainScreen().bounds.size.width - 20, 20))
22 | textEdit.delegate = self
23 | return textEdit
24 | }()
25 |
26 | func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
27 | if strlen(textView.text) + strlen(text) > 44 {
28 | return false
29 | }
30 | return true
31 | }
32 |
33 | override init(frame: CGRect) {
34 | super.init(frame: frame)
35 | title.text = "Create a new tag."
36 | self.addSubview(title)
37 | self.addSubview(textEdit)
38 | self.backgroundColor = UIColor.whiteColor()
39 | }
40 |
41 | required init(coder aDecoder: NSCoder) {
42 | fatalError("init(coder:) has not been implemented")
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/RRTagController/RRTagCollectionViewCell.swift:
--------------------------------------------------------------------------------
1 | //
2 | // RRTagCollectionViewCell.swift
3 | // RRTagController
4 | //
5 | // Created by Remi Robert on 20/02/15.
6 | // Copyright (c) 2015 Remi Robert. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | let RRTagCollectionViewCellIdentifier = "RRTagCollectionViewCellIdentifier"
12 |
13 | class RRTagCollectionViewCell: UICollectionViewCell {
14 |
15 | var isSelected: Bool = false
16 |
17 | lazy var textContent: UILabel! = {
18 | let textContent = UILabel(frame: CGRectZero)
19 | textContent.layer.masksToBounds = true
20 | textContent.layer.cornerRadius = 20
21 | textContent.layer.borderWidth = 2
22 | textContent.layer.borderColor = UIColor(red:0.88, green:0.88, blue:0.88, alpha:1).CGColor
23 | textContent.font = UIFont.boldSystemFontOfSize(17)
24 | textContent.textAlignment = NSTextAlignment.Center
25 | return textContent
26 | }()
27 |
28 | func initContent(tag: Tag) {
29 | self.contentView.addSubview(textContent)
30 | textContent.text = tag.textContent
31 | textContent.sizeToFit()
32 | textContent.frame.size.width = textContent.frame.size.width + 30
33 | textContent.frame.size.height = textContent.frame.size.height + 20
34 | isSelected = tag.isSelected
35 | textContent.backgroundColor = UIColor.clearColor()
36 | self.textContent.layer.backgroundColor = (self.isSelected == true) ? colorSelectedTag.CGColor : colorUnselectedTag.CGColor
37 | self.textContent.textColor = (self.isSelected == true) ? colorTextSelectedTag : colorTextUnSelectedTag
38 | }
39 |
40 | func initAddButtonContent() {
41 | self.contentView.addSubview(textContent)
42 | textContent.text = "+"
43 | textContent.sizeToFit()
44 | textContent.frame.size = CGSizeMake(40, 40)
45 | textContent.backgroundColor = UIColor.clearColor()
46 | self.textContent.layer.backgroundColor = UIColor.grayColor().CGColor
47 | self.textContent.textColor = UIColor.whiteColor()
48 | }
49 |
50 | func animateSelection(selection: Bool) {
51 | isSelected = selection
52 |
53 | self.textContent.frame.size = CGSizeMake(self.textContent.frame.size.width - 20, self.textContent.frame.size.height - 20)
54 | self.textContent.frame.origin = CGPointMake(self.textContent.frame.origin.x + 10, self.textContent.frame.origin.y + 10)
55 | UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 0.4, options: UIViewAnimationOptions.allZeros, animations: { () -> Void in
56 | self.textContent.layer.backgroundColor = (self.isSelected == true) ? colorSelectedTag.CGColor : colorUnselectedTag.CGColor
57 | self.textContent.textColor = (self.isSelected == true) ? colorTextSelectedTag : colorTextUnSelectedTag
58 | self.textContent.frame.size = CGSizeMake(self.textContent.frame.size.width + 20, self.textContent.frame.size.height + 20)
59 | self.textContent.center = CGPointMake(self.contentView.frame.size.width / 2, self.contentView.frame.size.height / 2)
60 | }, completion: nil)
61 | }
62 |
63 | class func contentHeight(content: String) -> CGSize {
64 | let styleText = NSMutableParagraphStyle()
65 | styleText.alignment = NSTextAlignment.Center
66 | let attributs = [NSParagraphStyleAttributeName:styleText, NSFontAttributeName:UIFont.boldSystemFontOfSize(17)]
67 | let sizeBoundsContent = (content as NSString).boundingRectWithSize(CGSizeMake(UIScreen.mainScreen().bounds.size.width,
68 | UIScreen.mainScreen().bounds.size.height), options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: attributs, context: nil)
69 | return CGSizeMake(sizeBoundsContent.width + 30, sizeBoundsContent.height + 20)
70 | }
71 | }
72 |
73 |
--------------------------------------------------------------------------------
/RRTagController/RRTagController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // RRTagController.swift
3 | // RRTagController
4 | //
5 | // Created by Remi Robert on 20/02/15.
6 | // Copyright (c) 2015 Remi Robert. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | struct Tag {
12 | var isSelected: Bool
13 | var isLocked: Bool
14 | var textContent: String
15 | }
16 |
17 | let colorUnselectedTag = UIColor.whiteColor()
18 | let colorSelectedTag = UIColor(red:0.22, green:0.7, blue:0.99, alpha:1)
19 |
20 | let colorTextUnSelectedTag = UIColor(red:0.33, green:0.33, blue:0.35, alpha:1)
21 | let colorTextSelectedTag = UIColor.whiteColor()
22 |
23 | class RRTagController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
24 |
25 | private var tags: Array!
26 | private var navigationBarItem: UINavigationItem!
27 | private var leftButton: UIBarButtonItem!
28 | private var rigthButton: UIBarButtonItem!
29 | private var _totalTagsSelected = 0
30 | private let addTagView = RRAddTagView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, 64))
31 | private var heightKeyboard: CGFloat = 0
32 |
33 | var blockFinih: ((selectedTags: Array, unSelectedTags: Array) -> ())!
34 | var blockCancel: (() -> ())!
35 |
36 | var totalTagsSelected: Int {
37 | get {
38 | return self._totalTagsSelected
39 | }
40 | set {
41 | if newValue == 0 {
42 | self._totalTagsSelected = 0
43 | return
44 | }
45 | self._totalTagsSelected += newValue
46 | self._totalTagsSelected = (self._totalTagsSelected < 0) ? 0 : self._totalTagsSelected
47 | self.navigationBarItem = UINavigationItem(title: "Tags")
48 | self.navigationBarItem.leftBarButtonItem = self.leftButton
49 | if (self._totalTagsSelected == 0) {
50 | self.navigationBarItem.rightBarButtonItem = nil
51 | }
52 | else {
53 | self.navigationBarItem.rightBarButtonItem = self.rigthButton
54 | }
55 | self.navigationBar.pushNavigationItem(self.navigationBarItem, animated: false)
56 | }
57 | }
58 |
59 | lazy var collectionTag: UICollectionView = {
60 | let layoutCollectionView = UICollectionViewFlowLayout()
61 | layoutCollectionView.sectionInset = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
62 | layoutCollectionView.itemSize = CGSizeMake(90, 20)
63 | layoutCollectionView.minimumLineSpacing = 10
64 | layoutCollectionView.minimumInteritemSpacing = 5
65 | let collectionTag = UICollectionView(frame: self.view.frame, collectionViewLayout: layoutCollectionView)
66 | collectionTag.contentInset = UIEdgeInsets(top: 84, left: 0, bottom: 20, right: 0)
67 | collectionTag.delegate = self
68 | collectionTag.dataSource = self
69 | collectionTag.backgroundColor = UIColor.whiteColor()
70 | collectionTag.registerClass(RRTagCollectionViewCell.self, forCellWithReuseIdentifier: RRTagCollectionViewCellIdentifier)
71 | return collectionTag
72 | }()
73 |
74 | lazy var addNewTagCell: RRTagCollectionViewCell = {
75 | let addNewTagCell = RRTagCollectionViewCell()
76 | addNewTagCell.contentView.addSubview(addNewTagCell.textContent)
77 | addNewTagCell.textContent.text = "+"
78 | addNewTagCell.frame.size = CGSizeMake(40, 40)
79 | addNewTagCell.backgroundColor = UIColor.grayColor()
80 | return addNewTagCell
81 | }()
82 |
83 | lazy var controlPanelEdition: UIView = {
84 | let controlPanel = UIView(frame: CGRectMake(0, UIScreen.mainScreen().bounds.size.height + 50, UIScreen.mainScreen().bounds.size.width, 50))
85 | controlPanel.backgroundColor = UIColor.whiteColor()
86 |
87 | let buttonCancel = UIButton(frame: CGRectMake(10, 10, 100, 30))
88 | buttonCancel.layer.borderColor = UIColor(red:0.88, green:0.88, blue:0.88, alpha:1).CGColor
89 | buttonCancel.layer.borderWidth = 2
90 | buttonCancel.backgroundColor = UIColor.whiteColor()
91 | buttonCancel.setTitle("Cancel", forState: UIControlState.Normal)
92 | buttonCancel.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
93 | buttonCancel.titleLabel?.font = UIFont.boldSystemFontOfSize(17)
94 | buttonCancel.layer.cornerRadius = 15
95 | buttonCancel.addTarget(self, action: "cancelEditTag", forControlEvents: UIControlEvents.TouchUpInside)
96 |
97 | let buttonAccept = UIButton(frame: CGRectMake(UIScreen.mainScreen().bounds.size.width - 110, 10, 100, 30))
98 | buttonAccept.layer.borderColor = UIColor(red:0.88, green:0.88, blue:0.88, alpha:1).CGColor
99 | buttonAccept.layer.borderWidth = 2
100 | buttonAccept.backgroundColor = UIColor.whiteColor()
101 | buttonAccept.setTitle("Create", forState: UIControlState.Normal)
102 | buttonAccept.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
103 | buttonAccept.titleLabel?.font = UIFont.boldSystemFontOfSize(17)
104 | buttonAccept.layer.cornerRadius = 15
105 | buttonAccept.addTarget(self, action: "createNewTag", forControlEvents: UIControlEvents.TouchUpInside)
106 |
107 | controlPanel.addSubview(buttonCancel)
108 | controlPanel.addSubview(buttonAccept)
109 | return controlPanel
110 | }()
111 |
112 | lazy var navigationBar: UINavigationBar = {
113 | let navigationBar = UINavigationBar(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, 64))
114 |
115 | self.navigationBarItem = UINavigationItem(title: "Tags")
116 | self.navigationBarItem.leftBarButtonItem = self.leftButton
117 |
118 | navigationBar.pushNavigationItem(self.navigationBarItem, animated: true)
119 | navigationBar.tintColor = colorSelectedTag
120 | return navigationBar
121 | }()
122 |
123 | func cancelTagController() {
124 | self.dismissViewControllerAnimated(true, completion: { () -> Void in
125 | self.blockCancel()
126 | })
127 | }
128 |
129 | func finishTagController() {
130 | var selected: Array = Array()
131 | var unSelected: Array = Array()
132 |
133 | for currentTag in tags {
134 | if currentTag.isSelected {
135 | selected.append(currentTag)
136 | }
137 | else {
138 | unSelected.append(currentTag)
139 | }
140 | }
141 | self.dismissViewControllerAnimated(true, completion: { () -> Void in
142 | self.blockFinih(selectedTags: selected, unSelectedTags: unSelected)
143 | })
144 | }
145 |
146 | func cancelEditTag() {
147 | self.view.endEditing(true)
148 | UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.4,
149 | initialSpringVelocity: 0.4, options: UIViewAnimationOptions.allZeros, animations: { () -> Void in
150 | self.addTagView.frame.origin.y = 0
151 | self.controlPanelEdition.frame.origin.y = UIScreen.mainScreen().bounds.size.height
152 | self.collectionTag.alpha = 1
153 | }) { (anim:Bool) -> Void in
154 |
155 | }
156 | }
157 |
158 | func createNewTag() {
159 | let spaceSet = NSCharacterSet.whitespaceCharacterSet()
160 | let contentTag = addTagView.textEdit.text.stringByTrimmingCharactersInSet(spaceSet)
161 | if strlen(contentTag) > 0 {
162 | let newTag = Tag(isSelected: false, isLocked: false, textContent: contentTag)
163 | tags.insert(newTag, atIndex: tags.count)
164 | collectionTag.reloadData()
165 | }
166 | cancelEditTag()
167 | }
168 |
169 | func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
170 | return tags.count + 1
171 | }
172 |
173 | func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
174 | sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
175 | if indexPath.row < tags.count {
176 | return RRTagCollectionViewCell.contentHeight(tags[indexPath.row].textContent)
177 | }
178 | return CGSizeMake(40, 40)
179 | }
180 |
181 | func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
182 | let selectedCell: RRTagCollectionViewCell? = collectionView.cellForItemAtIndexPath(indexPath) as? RRTagCollectionViewCell
183 |
184 | if indexPath.row < tags.count {
185 | var currentTag = tags[indexPath.row]
186 |
187 | if tags[indexPath.row].isSelected == false {
188 | tags[indexPath.row].isSelected = true
189 | selectedCell?.animateSelection(tags[indexPath.row].isSelected)
190 | totalTagsSelected = 1
191 | }
192 | else {
193 | tags[indexPath.row].isSelected = false
194 | selectedCell?.animateSelection(tags[indexPath.row].isSelected)
195 | totalTagsSelected = -1
196 | }
197 | }
198 | else {
199 | addTagView.textEdit.text = nil
200 | UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.4, initialSpringVelocity: 0.4,
201 | options: UIViewAnimationOptions.allZeros, animations: { () -> Void in
202 | self.collectionTag.alpha = 0.3
203 | self.addTagView.frame.origin.y = 64
204 | }, completion: { (anim: Bool) -> Void in
205 | self.addTagView.textEdit.becomeFirstResponder()
206 | println("")
207 | })
208 | }
209 | }
210 |
211 | func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
212 | let cell: RRTagCollectionViewCell? = collectionView.dequeueReusableCellWithReuseIdentifier(RRTagCollectionViewCellIdentifier, forIndexPath: indexPath) as? RRTagCollectionViewCell
213 |
214 | if indexPath.row < tags.count {
215 | let currentTag = tags[indexPath.row]
216 | cell?.initContent(currentTag)
217 | }
218 | else {
219 | cell?.initAddButtonContent()
220 | }
221 | return cell!
222 | }
223 |
224 | func keyboardWillShow(notification: NSNotification) {
225 | // TODO: change value
226 | if let userInfo = notification.userInfo {
227 | if let keyboardSize = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
228 | heightKeyboard = keyboardSize.height
229 | UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.4, initialSpringVelocity: 0.4,
230 | options: UIViewAnimationOptions.allZeros, animations: { () -> Void in
231 | self.controlPanelEdition.frame.origin.y = self.view.frame.size.height - self.heightKeyboard - 50
232 | }, completion: nil)
233 | }
234 | }
235 | else {
236 | heightKeyboard = 0
237 | }
238 | }
239 |
240 | func keyboardWillHide(notification: NSNotification) {
241 | heightKeyboard = 0
242 | }
243 |
244 | override func viewDidLoad() {
245 | super.viewDidLoad()
246 | self.view.backgroundColor = UIColor.whiteColor()
247 |
248 | leftButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.Done, target: self, action: "cancelTagController")
249 | rigthButton = UIBarButtonItem(title: "OK", style: UIBarButtonItemStyle.Done, target: self, action: "finishTagController")
250 |
251 | totalTagsSelected = 0
252 | self.view.addSubview(collectionTag)
253 | self.view.addSubview(addTagView)
254 | self.view.addSubview(controlPanelEdition)
255 | self.view.addSubview(navigationBar)
256 | NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name:UIKeyboardWillShowNotification, object: nil)
257 | NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: nil)
258 | }
259 |
260 | class func displayTagController(#parentController: UIViewController, tagsString: [String]?,
261 | blockFinish: (selectedTags: Array, unSelectedTags: Array)->(), blockCancel: ()->()) {
262 | let tagController = RRTagController()
263 | tagController.tags = Array()
264 | if tagsString != nil {
265 | for currentTag in tagsString! {
266 | tagController.tags.append(Tag(isSelected: false, isLocked: false, textContent: currentTag))
267 | }
268 | }
269 | tagController.blockCancel = blockCancel
270 | tagController.blockFinih = blockFinish
271 | parentController.presentViewController(tagController, animated: true, completion: nil)
272 | }
273 |
274 | class func displayTagController(#parentController: UIViewController, tags: [Tag]?,
275 | blockFinish: (selectedTags: Array, unSelectedTags: Array)->(), blockCancel: ()->()) {
276 | let tagController = RRTagController()
277 | tagController.tags = tags
278 | tagController.blockCancel = blockCancel
279 | tagController.blockFinih = blockFinish
280 | parentController.presentViewController(tagController, animated: true, completion: nil)
281 | }
282 |
283 | }
284 |
--------------------------------------------------------------------------------
/RRTagController/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // RRTagController
4 | //
5 | // Created by Remi Robert on 20/02/15.
6 | // Copyright (c) 2015 Remi Robert. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class ViewController: UIViewController {
12 |
13 | override func viewDidAppear(animated: Bool) {
14 | let tag = ["Albanie", "Allemagne", "Andorre", "Autriche-Hongrie", "Belgique", "Bulgarie", "Danemark", "Espagne", "France", "Grèce", "Italie", "Liechtenstein", "Luxembourg", "Monaco", "Monténégro", "Norvège", "Pays-Bas", "Portugal", "Roumanie", "Royaume-Uni", "Russie", "Saint-Marin", "Serbie", "Suède", "Suisse"]
15 |
16 | RRTagController.displayTagController(parentController: self, tagsString: tag, blockFinish: { (selectedTags, unSelectedTags) -> () in
17 | }) { () -> () in
18 | }
19 |
20 | }
21 |
22 | override func viewDidLoad() {
23 | super.viewDidLoad()
24 | }
25 |
26 | override func didReceiveMemoryWarning() {
27 | super.didReceiveMemoryWarning()
28 | }
29 |
30 |
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/RRTagControllerTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | com.remirobert.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/RRTagControllerTests/RRTagControllerTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // RRTagControllerTests.swift
3 | // RRTagControllerTests
4 | //
5 | // Created by Remi Robert on 20/02/15.
6 | // Copyright (c) 2015 Remi Robert. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | import XCTest
11 |
12 | class RRTagControllerTests: XCTestCase {
13 |
14 | override func setUp() {
15 | super.setUp()
16 | // Put setup code here. This method is called before the invocation of each test method in the class.
17 | }
18 |
19 | override func tearDown() {
20 | // Put teardown code here. This method is called after the invocation of each test method in the class.
21 | super.tearDown()
22 | }
23 |
24 | func testExample() {
25 | // This is an example of a functional test case.
26 | XCTAssert(true, "Pass")
27 | }
28 |
29 | func testPerformanceExample() {
30 | // This is an example of a performance test case.
31 | self.measureBlock() {
32 | // Put the code you want to measure the time of here.
33 | }
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/source/RRAddTagView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // RRAddTagView.swift
3 | // RRTagController
4 | //
5 | // Created by Remi Robert on 20/02/15.
6 | // Copyright (c) 2015 Remi Robert. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class RRAddTagView: UIView, UITextViewDelegate {
12 |
13 | lazy var title: UILabel = {
14 | let title = UILabel(frame: CGRectMake(10, 10, UIScreen.mainScreen().bounds.size.width - 20, 20))
15 | title.font = UIFont.boldSystemFontOfSize(18)
16 | title.textAlignment = NSTextAlignment.Center
17 | return title
18 | }()
19 |
20 | lazy var textEdit: UITextView = {
21 | let textEdit = UITextView(frame: CGRectMake(10, 30, UIScreen.mainScreen().bounds.size.width - 20, 20))
22 | textEdit.delegate = self
23 | return textEdit
24 | }()
25 |
26 | func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
27 | if strlen(textView.text) + strlen(text) > 44 {
28 | return false
29 | }
30 | return true
31 | }
32 |
33 | override init(frame: CGRect) {
34 | super.init(frame: frame)
35 | title.text = "Create a new tag."
36 | self.addSubview(title)
37 | self.addSubview(textEdit)
38 | self.backgroundColor = UIColor.whiteColor()
39 | }
40 |
41 | required init(coder aDecoder: NSCoder) {
42 | fatalError("init(coder:) has not been implemented")
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/source/RRTagCollectionViewCell.swift:
--------------------------------------------------------------------------------
1 | //
2 | // RRTagCollectionViewCell.swift
3 | // RRTagController
4 | //
5 | // Created by Remi Robert on 20/02/15.
6 | // Copyright (c) 2015 Remi Robert. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | let RRTagCollectionViewCellIdentifier = "RRTagCollectionViewCellIdentifier"
12 |
13 | class RRTagCollectionViewCell: UICollectionViewCell {
14 |
15 | var isSelected: Bool = false
16 |
17 | lazy var textContent: UILabel! = {
18 | let textContent = UILabel(frame: CGRectZero)
19 | textContent.layer.masksToBounds = true
20 | textContent.layer.cornerRadius = 20
21 | textContent.layer.borderWidth = 2
22 | textContent.layer.borderColor = UIColor(red:0.88, green:0.88, blue:0.88, alpha:1).CGColor
23 | textContent.font = UIFont.boldSystemFontOfSize(17)
24 | textContent.textAlignment = NSTextAlignment.Center
25 | return textContent
26 | }()
27 |
28 | func initContent(tag: Tag) {
29 | self.contentView.addSubview(textContent)
30 | textContent.text = tag.textContent
31 | textContent.sizeToFit()
32 | textContent.frame.size.width = textContent.frame.size.width + 30
33 | textContent.frame.size.height = textContent.frame.size.height + 20
34 | isSelected = tag.isSelected
35 | textContent.backgroundColor = UIColor.clearColor()
36 | self.textContent.layer.backgroundColor = (self.isSelected == true) ? colorSelectedTag.CGColor : colorUnselectedTag.CGColor
37 | self.textContent.textColor = (self.isSelected == true) ? colorTextSelectedTag : colorTextUnSelectedTag
38 | }
39 |
40 | func initAddButtonContent() {
41 | self.contentView.addSubview(textContent)
42 | textContent.text = "+"
43 | textContent.sizeToFit()
44 | textContent.frame.size = CGSizeMake(40, 40)
45 | textContent.backgroundColor = UIColor.clearColor()
46 | self.textContent.layer.backgroundColor = UIColor.grayColor().CGColor
47 | self.textContent.textColor = UIColor.whiteColor()
48 | }
49 |
50 | func animateSelection(selection: Bool) {
51 | isSelected = selection
52 |
53 | self.textContent.frame.size = CGSizeMake(self.textContent.frame.size.width - 20, self.textContent.frame.size.height - 20)
54 | self.textContent.frame.origin = CGPointMake(self.textContent.frame.origin.x + 10, self.textContent.frame.origin.y + 10)
55 | UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 0.4, options: UIViewAnimationOptions.allZeros, animations: { () -> Void in
56 | self.textContent.layer.backgroundColor = (self.isSelected == true) ? colorSelectedTag.CGColor : colorUnselectedTag.CGColor
57 | self.textContent.textColor = (self.isSelected == true) ? colorTextSelectedTag : colorTextUnSelectedTag
58 | self.textContent.frame.size = CGSizeMake(self.textContent.frame.size.width + 20, self.textContent.frame.size.height + 20)
59 | self.textContent.center = CGPointMake(self.contentView.frame.size.width / 2, self.contentView.frame.size.height / 2)
60 | }, completion: nil)
61 | }
62 |
63 | class func contentHeight(content: String) -> CGSize {
64 | let styleText = NSMutableParagraphStyle()
65 | styleText.alignment = NSTextAlignment.Center
66 | let attributs = [NSParagraphStyleAttributeName:styleText, NSFontAttributeName:UIFont.boldSystemFontOfSize(17)]
67 | let sizeBoundsContent = (content as NSString).boundingRectWithSize(CGSizeMake(UIScreen.mainScreen().bounds.size.width,
68 | UIScreen.mainScreen().bounds.size.height), options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: attributs, context: nil)
69 | return CGSizeMake(sizeBoundsContent.width + 30, sizeBoundsContent.height + 20)
70 | }
71 | }
72 |
73 |
--------------------------------------------------------------------------------
/source/RRTagController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // RRTagController.swift
3 | // RRTagController
4 | //
5 | // Created by Remi Robert on 20/02/15.
6 | // Copyright (c) 2015 Remi Robert. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | struct Tag {
12 | var isSelected: Bool
13 | var isLocked: Bool
14 | var textContent: String
15 | }
16 |
17 | let colorUnselectedTag = UIColor.whiteColor()
18 | let colorSelectedTag = UIColor(red:0.22, green:0.7, blue:0.99, alpha:1)
19 |
20 | let colorTextUnSelectedTag = UIColor(red:0.33, green:0.33, blue:0.35, alpha:1)
21 | let colorTextSelectedTag = UIColor.whiteColor()
22 |
23 | class RRTagController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
24 |
25 | private var tags: Array!
26 | private var navigationBarItem: UINavigationItem!
27 | private var leftButton: UIBarButtonItem!
28 | private var rigthButton: UIBarButtonItem!
29 | private var _totalTagsSelected = 0
30 | private let addTagView = RRAddTagView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, 64))
31 | private var heightKeyboard: CGFloat = 0
32 |
33 | var blockFinih: ((selectedTags: Array, unSelectedTags: Array) -> ())!
34 | var blockCancel: (() -> ())!
35 |
36 | var totalTagsSelected: Int {
37 | get {
38 | return self._totalTagsSelected
39 | }
40 | set {
41 | if newValue == 0 {
42 | self._totalTagsSelected = 0
43 | return
44 | }
45 | self._totalTagsSelected += newValue
46 | self._totalTagsSelected = (self._totalTagsSelected < 0) ? 0 : self._totalTagsSelected
47 | self.navigationBarItem = UINavigationItem(title: "Tags")
48 | self.navigationBarItem.leftBarButtonItem = self.leftButton
49 | if (self._totalTagsSelected == 0) {
50 | self.navigationBarItem.rightBarButtonItem = nil
51 | }
52 | else {
53 | self.navigationBarItem.rightBarButtonItem = self.rigthButton
54 | }
55 | self.navigationBar.pushNavigationItem(self.navigationBarItem, animated: false)
56 | }
57 | }
58 |
59 | lazy var collectionTag: UICollectionView = {
60 | let layoutCollectionView = UICollectionViewFlowLayout()
61 | layoutCollectionView.sectionInset = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
62 | layoutCollectionView.itemSize = CGSizeMake(90, 20)
63 | layoutCollectionView.minimumLineSpacing = 10
64 | layoutCollectionView.minimumInteritemSpacing = 5
65 | let collectionTag = UICollectionView(frame: self.view.frame, collectionViewLayout: layoutCollectionView)
66 | collectionTag.contentInset = UIEdgeInsets(top: 84, left: 0, bottom: 20, right: 0)
67 | collectionTag.delegate = self
68 | collectionTag.dataSource = self
69 | collectionTag.backgroundColor = UIColor.whiteColor()
70 | collectionTag.registerClass(RRTagCollectionViewCell.self, forCellWithReuseIdentifier: RRTagCollectionViewCellIdentifier)
71 | return collectionTag
72 | }()
73 |
74 | lazy var addNewTagCell: RRTagCollectionViewCell = {
75 | let addNewTagCell = RRTagCollectionViewCell()
76 | addNewTagCell.contentView.addSubview(addNewTagCell.textContent)
77 | addNewTagCell.textContent.text = "+"
78 | addNewTagCell.frame.size = CGSizeMake(40, 40)
79 | addNewTagCell.backgroundColor = UIColor.grayColor()
80 | return addNewTagCell
81 | }()
82 |
83 | lazy var controlPanelEdition: UIView = {
84 | let controlPanel = UIView(frame: CGRectMake(0, UIScreen.mainScreen().bounds.size.height + 50, UIScreen.mainScreen().bounds.size.width, 50))
85 | controlPanel.backgroundColor = UIColor.whiteColor()
86 |
87 | let buttonCancel = UIButton(frame: CGRectMake(10, 10, 100, 30))
88 | buttonCancel.layer.borderColor = UIColor(red:0.88, green:0.88, blue:0.88, alpha:1).CGColor
89 | buttonCancel.layer.borderWidth = 2
90 | buttonCancel.backgroundColor = UIColor.whiteColor()
91 | buttonCancel.setTitle("Cancel", forState: UIControlState.Normal)
92 | buttonCancel.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
93 | buttonCancel.titleLabel?.font = UIFont.boldSystemFontOfSize(17)
94 | buttonCancel.layer.cornerRadius = 15
95 | buttonCancel.addTarget(self, action: "cancelEditTag", forControlEvents: UIControlEvents.TouchUpInside)
96 |
97 | let buttonAccept = UIButton(frame: CGRectMake(UIScreen.mainScreen().bounds.size.width - 110, 10, 100, 30))
98 | buttonAccept.layer.borderColor = UIColor(red:0.88, green:0.88, blue:0.88, alpha:1).CGColor
99 | buttonAccept.layer.borderWidth = 2
100 | buttonAccept.backgroundColor = UIColor.whiteColor()
101 | buttonAccept.setTitle("Create", forState: UIControlState.Normal)
102 | buttonAccept.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
103 | buttonAccept.titleLabel?.font = UIFont.boldSystemFontOfSize(17)
104 | buttonAccept.layer.cornerRadius = 15
105 | buttonAccept.addTarget(self, action: "createNewTag", forControlEvents: UIControlEvents.TouchUpInside)
106 |
107 | controlPanel.addSubview(buttonCancel)
108 | controlPanel.addSubview(buttonAccept)
109 | return controlPanel
110 | }()
111 |
112 | lazy var navigationBar: UINavigationBar = {
113 | let navigationBar = UINavigationBar(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, 64))
114 |
115 | self.navigationBarItem = UINavigationItem(title: "Tags")
116 | self.navigationBarItem.leftBarButtonItem = self.leftButton
117 |
118 | navigationBar.pushNavigationItem(self.navigationBarItem, animated: true)
119 | navigationBar.tintColor = colorSelectedTag
120 | return navigationBar
121 | }()
122 |
123 | func cancelTagController() {
124 | self.dismissViewControllerAnimated(true, completion: { () -> Void in
125 | self.blockCancel()
126 | })
127 | }
128 |
129 | func finishTagController() {
130 | var selected: Array = Array()
131 | var unSelected: Array = Array()
132 |
133 | for currentTag in tags {
134 | if currentTag.isSelected {
135 | selected.append(currentTag)
136 | }
137 | else {
138 | unSelected.append(currentTag)
139 | }
140 | }
141 | self.dismissViewControllerAnimated(true, completion: { () -> Void in
142 | self.blockFinih(selectedTags: selected, unSelectedTags: unSelected)
143 | })
144 | }
145 |
146 | func cancelEditTag() {
147 | self.view.endEditing(true)
148 | UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.4,
149 | initialSpringVelocity: 0.4, options: UIViewAnimationOptions.allZeros, animations: { () -> Void in
150 | self.addTagView.frame.origin.y = 0
151 | self.controlPanelEdition.frame.origin.y = UIScreen.mainScreen().bounds.size.height
152 | self.collectionTag.alpha = 1
153 | }) { (anim:Bool) -> Void in
154 |
155 | }
156 | }
157 |
158 | func createNewTag() {
159 | let spaceSet = NSCharacterSet.whitespaceCharacterSet()
160 | let contentTag = addTagView.textEdit.text.stringByTrimmingCharactersInSet(spaceSet)
161 | if strlen(contentTag) > 0 {
162 | let newTag = Tag(isSelected: false, isLocked: false, textContent: contentTag)
163 | tags.insert(newTag, atIndex: tags.count)
164 | collectionTag.reloadData()
165 | }
166 | cancelEditTag()
167 | }
168 |
169 | func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
170 | return tags.count + 1
171 | }
172 |
173 | func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
174 | sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
175 | if indexPath.row < tags.count {
176 | return RRTagCollectionViewCell.contentHeight(tags[indexPath.row].textContent)
177 | }
178 | return CGSizeMake(40, 40)
179 | }
180 |
181 | func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
182 | let selectedCell: RRTagCollectionViewCell? = collectionView.cellForItemAtIndexPath(indexPath) as? RRTagCollectionViewCell
183 |
184 | if indexPath.row < tags.count {
185 | var currentTag = tags[indexPath.row]
186 |
187 | if tags[indexPath.row].isSelected == false {
188 | tags[indexPath.row].isSelected = true
189 | selectedCell?.animateSelection(tags[indexPath.row].isSelected)
190 | totalTagsSelected = 1
191 | }
192 | else {
193 | tags[indexPath.row].isSelected = false
194 | selectedCell?.animateSelection(tags[indexPath.row].isSelected)
195 | totalTagsSelected = -1
196 | }
197 | }
198 | else {
199 | addTagView.textEdit.text = nil
200 | UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.4, initialSpringVelocity: 0.4,
201 | options: UIViewAnimationOptions.allZeros, animations: { () -> Void in
202 | self.collectionTag.alpha = 0.3
203 | self.addTagView.frame.origin.y = 64
204 | }, completion: { (anim: Bool) -> Void in
205 | self.addTagView.textEdit.becomeFirstResponder()
206 | println("")
207 | })
208 | }
209 | }
210 |
211 | func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
212 | let cell: RRTagCollectionViewCell? = collectionView.dequeueReusableCellWithReuseIdentifier(RRTagCollectionViewCellIdentifier, forIndexPath: indexPath) as? RRTagCollectionViewCell
213 |
214 | if indexPath.row < tags.count {
215 | let currentTag = tags[indexPath.row]
216 | cell?.initContent(currentTag)
217 | }
218 | else {
219 | cell?.initAddButtonContent()
220 | }
221 | return cell!
222 | }
223 |
224 | func keyboardWillShow(notification: NSNotification) {
225 | // TODO: change value
226 | if let userInfo = notification.userInfo {
227 | if let keyboardSize = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
228 | heightKeyboard = keyboardSize.height
229 | UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.4, initialSpringVelocity: 0.4,
230 | options: UIViewAnimationOptions.allZeros, animations: { () -> Void in
231 | self.controlPanelEdition.frame.origin.y = self.view.frame.size.height - self.heightKeyboard - 50
232 | }, completion: nil)
233 | }
234 | }
235 | else {
236 | heightKeyboard = 0
237 | }
238 | }
239 |
240 | func keyboardWillHide(notification: NSNotification) {
241 | heightKeyboard = 0
242 | }
243 |
244 | override func viewDidLoad() {
245 | super.viewDidLoad()
246 | self.view.backgroundColor = UIColor.whiteColor()
247 |
248 | leftButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.Done, target: self, action: "cancelTagController")
249 | rigthButton = UIBarButtonItem(title: "OK", style: UIBarButtonItemStyle.Done, target: self, action: "finishTagController")
250 |
251 | totalTagsSelected = 0
252 | self.view.addSubview(collectionTag)
253 | self.view.addSubview(addTagView)
254 | self.view.addSubview(controlPanelEdition)
255 | self.view.addSubview(navigationBar)
256 | NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name:UIKeyboardWillShowNotification, object: nil)
257 | NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: nil)
258 | }
259 |
260 | class func displayTagController(#parentController: UIViewController, tagsString: [String]?,
261 | blockFinish: (selectedTags: Array, unSelectedTags: Array)->(), blockCancel: ()->()) {
262 | let tagController = RRTagController()
263 | tagController.tags = Array()
264 | if tagsString != nil {
265 | for currentTag in tagsString! {
266 | tagController.tags.append(Tag(isSelected: false, isLocked: false, textContent: currentTag))
267 | }
268 | }
269 | tagController.blockCancel = blockCancel
270 | tagController.blockFinih = blockFinish
271 | parentController.presentViewController(tagController, animated: true, completion: nil)
272 | }
273 |
274 | class func displayTagController(#parentController: UIViewController, tags: [Tag]?,
275 | blockFinish: (selectedTags: Array, unSelectedTags: Array)->(), blockCancel: ()->()) {
276 | let tagController = RRTagController()
277 | tagController.tags = tags
278 | tagController.blockCancel = blockCancel
279 | tagController.blockFinih = blockFinish
280 | parentController.presentViewController(tagController, animated: true, completion: nil)
281 | }
282 |
283 | }
284 |
--------------------------------------------------------------------------------
/source/anim.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/remirobert/RRTagController/dacd7fabe302a3213677d1c9441bf4568cda9f38/source/anim.gif
--------------------------------------------------------------------------------
/source/banner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/remirobert/RRTagController/dacd7fabe302a3213677d1c9441bf4568cda9f38/source/banner.png
--------------------------------------------------------------------------------