@@ -42,6 +42,8 @@ import UIKit
4242 @objc optional func tokenField( _ tokenField: ICTokenField , didCompleteText text: String )
4343 /// Tells the delegate that the token at certain index is removed from the token field.
4444 @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
4547}
4648
4749
@@ -299,12 +301,12 @@ open class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDelega
299301 }
300302
301303 let index = text. index ( text. endIndex, offsetBy: - delimiter. characters. count)
302- let newToken = text. substring ( to: index)
304+ let newText = text. substring ( to: index)
303305
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 ) )
306308 layoutTokenTextField ( )
307- delegate? . tokenField ? ( self , didCompleteText: newToken )
309+ delegate? . tokenField ? ( self , didCompleteText: newText )
308310 }
309311
310312 textField. text = nil
@@ -373,6 +375,14 @@ open class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDelega
373375
374376 // MARK: - Private Methods
375377
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+
376386 /// Returns true if any highlighted token is found and removed, otherwise false.
377387 private func removeHighlightedToken( ) -> Bool {
378388 for (index, token) in tokens. enumerated ( ) {
@@ -452,7 +462,7 @@ open class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDelega
452462 }
453463
454464 inputTextField. text = nil
455- tokens. append ( ICToken ( text : text, normalAttributes : normalTokenAttributes , highlightedAttributes : highlightedTokenAttributes ) )
465+ tokens. append ( customizedToken ( with : text) )
456466 layoutTokenTextField ( )
457467 delegate? . tokenField ? ( self , didCompleteText: text)
458468 }
0 commit comments