A token field implementation for iOS

Overview

ResizingTokenField

Build Status Version License Platform

A token field implementation written in Swift 5.

Example GIF

Features

  • Can be used in Interface Builder or created programmatically
  • Uses a UICollectionView to display tokens, allowing token changes to be animated
  • Automatically updates intrinsic height as content is added and removed
  • Supports collapsing tokens into a text description
  • Allows providing a custom UICollectionViewCell for tokens

Installation

Cocoapods

ResizingTokenField is available through CocoaPods. To install it, add the following to your Podfile:

pod 'ResizingTokenField', '~> 0.1.1'

Carthage

To install via Carthage, add the following to your Cartfile:

github "tadejr/ResizingTokenField" "0.1.1"

Usage

The token field can be used via Interface Builder - add an empty UIView to your layout and set its class to ResizingTokenField. It can also be initialized programmatically by using init(frame:).

Meant to be used with auto layout; it provides intrinsic content height, meaning you only need to pin its position and width, height will change automatically as content is added and removed from the field. In Interface Builder, the Placeholder Intrinsic Size setting can be used for height.

Configuration

Customization is possible by setting appropriate properties on a ResizingTokenField instance. Additionally, three different delegates can be set to handle specific behaviour. Check the example project for more info.

Rotation support

The token field does not automatically invalidate layout when its bounds change. To handle device rotation you should manually invalidate layout.

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)
    tokenField.invalidateLayout()   
}

Height change animation

To animate changes to the token field's height you should call layoutIfNeeded() on an appropriate superview when token field intrinsic height changes.

func resizingTokenField(_ tokenField: ResizingTokenField, willChangeIntrinsicHeight newHeight: CGFloat) {
    view.layoutIfNeeded()
}

func resizingTokenField(_ tokenField: ResizingTokenField, didChangeIntrinsicHeight newHeight: CGFloat) {
    UIView.animate(withDuration: tokenField.animationDuration) {
        self.view.layoutIfNeeded()
    }
}

Author

Tadej Razborsek, [email protected]

License

ResizingTokenField is available under the MIT license. See the LICENSE file for more info.

You might also like...
A message bar for iOS written in Swift.
A message bar for iOS written in Swift.

Dodo, a message bar for iOS / Swift This is a UI widget for showing text messages in iOS apps. It is useful for showing short messages to the user, so

Protocol oriented, type safe, scalable design system foundation swift framework for iOS.
Protocol oriented, type safe, scalable design system foundation swift framework for iOS.

Doric: Design System Foundation Design System foundation written in Swift. Protocol oriented, type safe, scalable framework for iOS. Features Requirem

A Material Design drop down for iOS
A Material Design drop down for iOS

A Material Design drop down for iOS written in Swift. Demo Do pod try DropDown in your console and run the project to try a demo. To install CocoaPods

An easy to use FAQ view for iOS written in Swift
An easy to use FAQ view for iOS written in Swift

FAQView An easy to use FAQ view for iOS written in Swift. This view is a subclass of UIView. Setup with CocoaPods If you are using CocoaPods add this

A custom reusable circular / progress slider control for iOS application.
A custom reusable circular / progress slider control for iOS application.

HGCircularSlider Example To run the example project, clone the repo, and run pod install from the Example directory first. You also may like HGPlaceho

A customizable color picker for iOS in Swift
A customizable color picker for iOS in Swift

IGColorPicker is a fantastic color picker 🎨 written in Swift. Table of Contents Documentation Colors Style Other features Installation Example Gettin

⚡️ A library of widgets and helpers to build instant-search applications on iOS.
⚡️ A library of widgets and helpers to build instant-search applications on iOS.

By Algolia. InstantSearch family: InstantSearch iOS | InstantSearch Android | React InstantSearch | InstantSearch.js | Angular InstantSearch | Vue Ins

An iOS picker view to serve all your
An iOS picker view to serve all your "picking" needs

Mandoline The PickerView is a UICollectionView that provides a smooth "picking" interface. In order to get the most out of it, a consuming view contro

A draggable modal for iOS Applications.
A draggable modal for iOS Applications.

Mantle Modal Draggable Modal, PopUp or Menu written in Swift. Description A simple modal resource that uses a UIScrollView to allow the user to close

Comments
  • How to Change the color of the selected tag?

    How to Change the color of the selected tag?

    I am using this library to add users in a group. I am facing an issue if I want to remove the user, actually I want to change the select tag text color and backdroud color of the tag when I select the already added tags. Appreciate for your help

    opened by NallapatiMalleswari 1
  • Automatic Scroll

    Automatic Scroll

    I have my token field with fixed height is there a way to make it scroll automatically when new lines is added so the last thing inserted is the visible thing and thankns

    opened by Ahmed-Masoud 5
  • Fit token without expanding field

    Fit token without expanding field

    @tadejr Hey, I have a use case where I only add one token in the field so I have no need for the field to expand. Except it does when the token text has a certain number of characters. in my case its only 13 characters and comes no were to filling the full width of the textField yet the tokenField still expands. How can I stop the tokenField from expanding?

    opened by otymartin 5
Releases(0.1.1)
  • 0.1.1(Jul 9, 2019)

  • 0.1.0(Jul 2, 2019)

    Features

    • Can be used in Interface Builder or created programmatically
    • Uses a UICollectionView to display tokens, allowing token changes to be animated
    • Automatically updates intrinsic height as content is added and removed
    • Supports collapsing tokens into a text description
    • Allows providing a custom UICollectionViewCell for tokens
    Source code(tar.gz)
    Source code(zip)
Owner
Tadej Razboršek
Tadej Razboršek
Swipe Left2Right & Right2Left, pure SwiftUI implementation

SwipeCell Preview Features Swipe cell from Left2Right & Right2Left. Destructive swipe Usage Simply add onSwipe(leading, trailing) method to your list

Enes Karaosman 266 Jan 6, 2023
Swift programming language hackathon. Implementation of the main logic of working with an ATM in the Playground environment.

Hackaton-ATM-PJ04 Swift programming language hackathon. Implementation of the main logic of working with an ATM in the Playground environment. The tas

Raman Kozar 2 Oct 4, 2022
UIStackView replica for iOS 7.x and iOS 8.x

TZStackView A wonderful layout component called the UIStackView was introduced with iOS 9. With this component it is really easy to layout components

Tom van Zummeren 1.2k Oct 10, 2022
Super awesome Swift minion for Core Data (iOS, macOS, tvOS)

⚠️ Since this repository is going to be archived soon, I suggest migrating to NSPersistentContainer instead (available since iOS 10). For other conven

Marko Tadić 306 Sep 23, 2022
A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView and iPhone X safe area support for content reloading. Built for iOS 10 and later.

Arale A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView support for reloading your content. Built f

Putra Z. 43 Feb 4, 2022
BulletinBoard is an iOS library that generates and manages contextual cards displayed at the bottom of the screen

BulletinBoard is an iOS library that generates and manages contextual cards displayed at the bottom of the screen. It is especially well

Alexis (Aubry) Akers 5.3k Jan 2, 2023
💾 A collection of classic-style UI components for iOS

A collection of classic-style UI components for UIKit, influenced by Windows 95 Introduction This is a little exploration into applying '90s-era desig

Blake Tsuzaki 2.2k Dec 22, 2022
A simple, customizable view for efficiently collecting country information in iOS apps.

CountryPickerView CountryPickerView is a simple, customizable view for selecting countries in iOS apps. You can clone/download the repository and run

Kizito Nwose 459 Dec 27, 2022
A library to recreate the iOS Apple Music now playing transition

DeckTransition DeckTransition is an attempt to recreate the card-like transition found in the iOS 10 Apple Music and iMessage apps. Hereʼs a GIF showi

Harshil Shah 2.2k Dec 15, 2022