Giter Site home page Giter Site logo

resizingtokenfield's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.