Swiftpack.co - Package - whitesmith/WSTagsField

WSTagsField

Carthage Compatible CocoaPods Compatible Swift 5 Platforms iOS Build Status License MIT

An iOS text field that represents different Tags.

WSTagsField

Usage

let tagsField = WSTagsField()
tagsField.layoutMargins = UIEdgeInsets(top: 2, left: 6, bottom: 2, right: 6)
tagsField.contentInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
tagsField.spaceBetweenLines = 5.0
tagsField.spaceBetweenTags = 10.0
tagsField.font = .systemFont(ofSize: 12.0)
tagsField.backgroundColor = .white
tagsField.tintColor = .green
tagsField.textColor = .black
tagsField.fieldTextColor = .blue
tagsField.selectedColor = .black
tagsField.selectedTextColor = .red
tagsField.delimiter = ","
tagsField.isDelimiterVisible = true
tagsField.placeholderColor = .green
tagsField.placeholderAlwaysVisible = true
tagsField.returnKeyType = .next
tagsField.acceptTagOption = .space

// Events
tagsField.onDidAddTag = { field, tag in
    print("DidAddTag", tag.text)
}

tagsField.onDidRemoveTag = { field, tag in
    print("DidRemoveTag", tag.text)
}

tagsField.onDidChangeText = { _, text in
    print("DidChangeText")
}

tagsField.onDidChangeHeightTo = { _, height in
    print("HeightTo", height)
}

tagsField.onValidateTag = { tag, tags in
    // custom validations, called before tag is added to tags list
    return tag.text != "#" && !tags.contains(where: { $0.text.uppercased() == tag.text.uppercased() })
}

print("List of Tags Strings:", tagsField.tags.map({$0.text}))

Installation

Carthage

To install it, simply add the following line to your Cartfile:

github "whitesmith/WSTagsField"

Then run carthage update.

Follow the current instructions in Carthage's README for up to date installation instructions.

CocoaPods

To install it, simply add the following line to your Podfile:

pod "WSTagsField"

You will also need to make sure you're opting into using frameworks:

use_frameworks!

Then run pod install with CocoaPods 1.6.0 or newer.

Manually

Download all the source files and drop them into your project.

Requirements

  • iOS 9.0+
  • Xcode 10 (Swift 4)

Contributing

The best way to contribute is by submitting a pull request. We'll do our best to respond to your patch as soon as possible. You can also submit a new GitHub issue if you find bugs or have questions. :octocat:

Credits

Whitesmith

This project was inspired by CLTokenInputView.

Github

link
Stars: 846
Help us keep the lights on

Dependencies

Used By

Total: 1

Releases

5.0.0 - May 7, 2019

Changes included:

  • #112 Swift 5 (Xcode 10.2)
  • #107 Open field.textContentType access.

CocoaPods

pod 'WSTagsField', '~> 5.0'

Carthage

github "whitesmith/WSTagsField" ~> 5.0

4.1.0 - Feb 21, 2019

Changes included:

  • #110 Add method to reload input views (ty @jamesyorke)

CocoaPods

pod 'WSTagsField', '~> 4.1'

Carthage

github "whitesmith/WSTagsField" ~> 4.1

3.2.0 - Sep 14, 2018

Changes

  • Fix of KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED crash #103 & #101
  • #99 Add an option to stop WSTagsField from becoming scrollable (ty @bellebethcooper)
  • #95 Make keyboard appearance type open (ty @tim289)

4.0.0 - Sep 14, 2018

CocoaPods

pod 'WSTagsField', '~> 4.0'

Carthage

github "whitesmith/WSTagsField" ~> 4.0

3.1.0 - Apr 9, 2018

Changes

  • By default, the return key is used to create a tag in the field. Now, you can change it and use the comma or the space key instead: tagsField.acceptTagOption = .space.
  • onDidEndEditing and onDidBeginEditing events were removed in favor of UITextFieldDelegate methods (textFieldDidBeginEditing(textField:) and textFieldDidEndEditing(textField:)). The delegate should be assigned to the textDelegate property and it's related with the input text field. It's also a nice way to have access to textFieldShouldReturn(textField:) where it's possible to change the first responder when the return key is free (i.e.: tagsField.acceptTagOption = .comma is set).