@@ -42,6 +42,8 @@ import UIKit
42
42
@objc optional func tokenField( _ tokenField: ICTokenField , didCompleteText text: String )
43
43
/// Tells the delegate that the token at certain index is removed from the token field.
44
44
@objc optional func tokenField( _ tokenField: ICTokenField , didDeleteText text: String , atIndex index: Int )
45
+ /// Asks the delegate for the subsequent delimiter string for a completed text in the token field.
46
+ @objc optional func tokenField( _ tokenField: ICTokenField , subsequentDelimiterForCompletedText text: String ) -> String
45
47
}
46
48
47
49
@@ -299,12 +301,12 @@ open class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDelega
299
301
}
300
302
301
303
let index = text. index ( text. endIndex, offsetBy: - delimiter. characters. count)
302
- let newToken = text. substring ( to: index)
304
+ let newText = text. substring ( to: index)
303
305
304
- if !newToken . isEmpty && newToken != delimiter && ( delegate? . tokenField ? ( self , shouldCompleteText: newToken ) ?? true ) {
305
- tokens. append ( ICToken ( text : newToken , normalAttributes : normalTokenAttributes , highlightedAttributes : highlightedTokenAttributes ) )
306
+ if !newText . isEmpty && newText != delimiter && ( delegate? . tokenField ? ( self , shouldCompleteText: newText ) ?? true ) {
307
+ tokens. append ( customizedToken ( with : newText ) )
306
308
layoutTokenTextField ( )
307
- delegate? . tokenField ? ( self , didCompleteText: newToken )
309
+ delegate? . tokenField ? ( self , didCompleteText: newText )
308
310
}
309
311
310
312
textField. text = nil
@@ -373,6 +375,14 @@ open class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDelega
373
375
374
376
// MARK: - Private Methods
375
377
378
+ private func customizedToken( with text: String ) -> ICToken {
379
+ if let string = delegate? . tokenField ? ( self , subsequentDelimiterForCompletedText: text) {
380
+ return ICToken ( text: text, delimiter: string, normalAttributes: normalTokenAttributes, highlightedAttributes: highlightedTokenAttributes)
381
+ } else {
382
+ return ICToken ( text: text, normalAttributes: normalTokenAttributes, highlightedAttributes: highlightedTokenAttributes)
383
+ }
384
+ }
385
+
376
386
/// Returns true if any highlighted token is found and removed, otherwise false.
377
387
private func removeHighlightedToken( ) -> Bool {
378
388
for (index, token) in tokens. enumerated ( ) {
@@ -452,7 +462,7 @@ open class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDelega
452
462
}
453
463
454
464
inputTextField. text = nil
455
- tokens. append ( ICToken ( text : text, normalAttributes : normalTokenAttributes , highlightedAttributes : highlightedTokenAttributes ) )
465
+ tokens. append ( customizedToken ( with : text) )
456
466
layoutTokenTextField ( )
457
467
delegate? . tokenField ? ( self , didCompleteText: text)
458
468
}
0 commit comments