Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Example/CustomizedTokenField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class CustomizedTokenField: ICTokenField {
applyCustomizedStyle()
}

override var intrinsicContentSize: CGSize {
return UILayoutFittingExpandedSize
}

}


Expand Down
15 changes: 14 additions & 1 deletion Example/CustomizedTokenViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,20 @@ class CustomizedTokenViewController: UIViewController, ICTokenFieldDelegate {
cancelBarButton.tintColor = UIColor.white
navigationItem.rightBarButtonItem = cancelBarButton

navigationItem.titleView = tokenField
navigationItem.titleView = {
if #available(iOS 11, *) {
tokenField.translatesAutoresizingMaskIntoConstraints = false
let views = ["field": tokenField]
let metrics = ["padding": 7]
let containerView = UIView()
containerView.addSubview(tokenField)
containerView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[field]-padding-|", options: [], metrics: metrics, views: views))
containerView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-padding-[field]-padding-|", options: [], metrics: metrics, views: views))
return containerView
} else {
return tokenField
}
}()
tokenField.delegate = self
}

Expand Down
1 change: 1 addition & 0 deletions Example/ExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ExampleViewController: UITableViewController {

override func loadView() {
super.loadView()
tableView.rowHeight = 44
tableView.register(ExampleCell.self, forCellReuseIdentifier: String(describing: ExampleCell.self))
tableView.tableFooterView = flipButton
tableView.tableFooterView?.isUserInteractionEnabled = true
Expand Down
14 changes: 10 additions & 4 deletions Source/TokenField/ICTokenField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -328,19 +328,25 @@ open class ICTokenField: UIView, UITextFieldDelegate, ICBackspaceTextFieldDelega
// MARK: - ICBackspaceTextFieldDelegate

@nonobjc func textFieldShouldDelete(_ textField: ICBackspaceTextField) -> Bool {
if tokens.isEmpty {
if !textField.showsCursor {
_ = removeHighlightedToken()
return true
}

if !textField.showsCursor {
_ = removeHighlightedToken()
guard let text = textField.text else {
return true
}

if let text = textField.text, text.isEmpty {
if text.isEmpty {
textField.showsCursor = false
tokens.last?.isHighlighted = true
} else {
// textField(_:shouldChangeCharactersIn:replacementString:) is skipped when the delete key is pressed.
// Notify the delegate of the changed input text manually.
let index = text.index(text.endIndex, offsetBy: -1)
delegate?.tokenField?(self, didChangeInputText: text.substring(to: index))
}

return true
}

Expand Down