Coder Social home page Coder Social logo

nekonora / taggerkit Goto Github PK

View Code? Open in Web Editor NEW
465.0 8.0 40.0 819 KB

🏷 TaggerKit helps you to quickly implement tags in your UIKit apps, so you can go on and test your idea without having to worry about logic and custom collection layouts.

License: MIT License

Ruby 4.50% Swift 95.50%
swift carthage cocoapods swiftpackagemanager tags ios

taggerkit's Introduction

TaggerKit

Version License Platform

TaggerKit helps you quickly integrate tags into your iOS projects. It provides a collection view for displaying tags and a text field for adding them to another collection view. The custom layout used by TaggerKit is based on TagCellLayout by Ritesh Gupta.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

TaggerKit is writtern is compatible with Swift 4.2/5 and runs on iOS 11+.

Changelog

0.6.1

• Added support for Swift Package Manager; • Fixed a bug that was causing a tag view to not send tags to another one by tapping the button; • Added a convenience init method to create a tag view more quickly;

0.6

tagIsBeingAdded and tagIsBeingRemoved methods are not accessible by override from UIViewControllers. This is because UIViewController is not a delegate of TKViewController anymore. If you want to use these methods you can still make your controller conform to the TKCollectionViewDelegate protocol; • Custom properties customTagBorderWidth and customTagBorderColor can now be set; • Added Carthage support; • iOS 13, Xcode 11, Swift 5.1 support; • Some code refactored;

Installation

TaggerKit is available through CocoaPods, Carthage or SPM.

To install the latest version, just add the following line to your Podfile:

pod 'TaggerKit'

In your Cartfile:

github "nekonora/TaggerKit" ~> 0.6.0

Or add this repo as a swift package inside of Xcode 11.

Setup

Static tags

Tags can be implemented in a couple of ways. Let's start simple: you have a bunch of tags (Strings) that you want to show to the user. A static collection view is just what we need.

  1. In Interface Builder, create a container view in your ViewController and then delete its child from the storyboard:

Interface Builder container view

  1. Import TaggerKit into your view controller and create an outlet for the container view

    import TaggerKit
    
    	class ViewController: UIViewController {
    
    		@IBOutlet var containerView: UIView!
    
    
  2. Instantiate and a TKCollectionView() and give it to the container with:

    var tagCollection = TKCollectionView()
    
    override func viewDidLoad() {
    	super.viewDidLoad()
    
    	add(tagCollection, toView: containerView)
  3. Give the collection view some tags:

    	tagCollection.tags = ["Some", "Tag", "For", "You"]
  4. Done!

Dynamic tags

Do this if you want what you saw in the preview GIF.

  1. Follow the instructions above and create two collection views, putting them into two different containers

  2. For both collection views set their .action property accordingly. For example: if you are in a view displaying a product to which your user has already added some tags, these tags should be removable, hence that collection's action should be .removeAction (more on how to be notified of tags events later).

    productTagsCollection.action 	= .removeTag
  3. Create a Text Field outlet and set its custom class to TKTextField

  4. Set the text field's .sender and .receiver properties. This enables the text field to add tags to a collection. The sender is a collection view that is displaying tags from the textfield (tags that should be filtered), while the receiver is the collection receiving the tags:

    textField.sender = allTagsCollection
    textField.receiver = productTagsCollection
  5. If you want the "filter" collection to be able to add tags, set these properties:

    allTagsCollection.action = .addTag
    allTagsCollection.receiver = productTagsCollection
  6. Lastly, you probably want to be notified and act upon tags being added or removed from a collection. For this purpose, TaggerKit lets you override these two methods in order to add your functionality (your controller must the delegate of the collections):

    allTagsCollection.delegate 	= self
    productTagsCollection.delegate 	= self
    
    
    override func tagIsBeingAdded(name: String?) {
    	// Example: save testCollection.tags to UserDefault
    	print("added \(name!)")
    }
    
    override func tagIsBeingRemoved(name: String?) {
    	print("removed \(name!)")
    }

Customisation

TKCollectionView has some properties you can set to modify the tag's appearance:

// Custom font
	tagCollection.customFont = UIFont.boldSystemFont(ofSize: 14)
// Corner radius of tags	
	tagCollection.customCornerRadius = 14.0		
// Spacing between cells					
	tagCollection.customSpacing = 20.0	
// Background of cells						
	tagCollection.customBackgroundColor = UIColor.red	
// Border for cells
    tagCollection.customTagBorderColor = UIColor.red
    tagCollection.customTagBorderSize = 2

taggerkit's People

Contributors

nekonora avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

taggerkit's Issues

Change text color

Screenshot 2021-01-07 at 9 13 47 AM
Is there a way of changing the text color? Like productTags.customTextColor = .red

update tagview to dropdown

update tagview to dropdown

hello, after used project, i think better is change allTags view with dropdown for more flexible and comfortable, can u give me some advice to do it? Thanks

macOS

Please add support for macOS.

Unable to add New Tag

Hi,

I was try to add new tag in tagCollection, but it would not add for me.

var toTagCollection = TKCollectionView()

add(toTagCollection, toView: toEmailContainerView!)
toTagCollection.delegate = self
toTagCollection.action = .removeTag

func textFieldShouldReturn(_ textField: UITextField) -> Bool {

       toTagCollection.addNewTag(named: textField.text)

    return true
}

Any things, I am missing here!

Unknown Process Name warning messages

This is a great control. Thank you. However, I'm getting a slew of warning messages:

TaggerKit_Example[12045:882350] [Unknown process name] CGContextDrawPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

This is 10.14.6, but using Xcode11.0.

text color

i do not see how to change the text color

update alltag view

hello, after used project, i think better is change allTags view with dropdown for more flexible and comfortable, can u give me some advice to do it? Thanks

SPM support

Would be great to have SPM supported, is this something you'd want a PR for?

Support horizontal scroll

Hi @nekonora,

I change your TagCellLayout to inherited from UICollectionViewFlowLayout and change the scroll direction of the collection view but it works. Do you have any ideas to help do that?

Drag&Drop support

I'm thinking on how drag&drop would work and/or if it's useful for moving/adding tags between tag views.

Simpler, more manageable collection object

A new simpler container for tags, a simple (IB-friendly) UIView subclass that doesn't need to be added as a child controller. Although the old method will still be available for the time being, it will be deprecated by this.

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.