Code Monkey home page Code Monkey logo

htagview's Introduction

HTagView

Version License Platform

HTagView is a customized tag view sublassing UIView where tag could be either with cancel button or multiseletable.

Features

  • .cancel and .select tag types available (see below)
  • Single / Multi selection for .select tags
  • HTagViewDataSource and HTagViewDelegte protocols
  • Customized configuration
  • Supporting @IBDesignable and autolayout
  • Specific/Auto tag width
  • Specific/Auto Maximum tag width

Demo

Example

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

Installation

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

pod "HTagView"

Requirements

Swift Version HTagView Version
Swift 2.3 2.0.x
Swift 3.0 2.1.0 or later

Usage

Configure HTagView

These properties support @IBDesignable as well.

override func viewDidLoad(){
	super.viewDidLoad()
	//.
	//.
	//.

	// configure tagView
	tagView.delegate = self
	tagView.dataSource = self
	tagView.marg = 20
	tagView.btwTags = 20
	tagView.btwLines = 20
	tagView.tagFont = UIFont.systemFont(ofSize: 15)
	tagView.tagMainBackColor = UIColor(red: 1, green: 130/255, blue: 103/255, alpha: 1)
	tagView.tagSecondBackColor = UIColor.lightGray
	tagView.tagSecondTextColor = UIColor.darkText
	tagView.tagContentEdgeInsets = UIEdgeInsets(top: 10, left: 20, bottom: 10, right: 20)
	tagView.tagMaximumWidth = .HTagAutoMaximumWidth
	tagView.tagBorderColor = UIColor.black.cgColor
	tagView.tagBorderWidth = 2
}

Data Source

class ViewController: UIViewController, HTagViewDataSource{
	// .
	// .
	// .

    // MARK: - Data
    let data = ["Hey!","This","is","a","HTagView."]

    
    // MARK: - HTagViewDataSource
    func numberOfTags(_ tagView: HTagView) -> Int {
    	return data.count
    }
    
    func tagView(_ tagView: HTagView, titleOfTagAtIndex index: Int) -> String {
        return data[index]
    }
    
    func tagView(_ tagView: HTagView, tagTypeAtIndex index: Int) -> HTagType {
		return .select
		// return .cancel
    }
    
    func tagView(_ tagView: HTagView, tagWidthAtIndex index: Int) -> CGFloat {
        return .HTagAutoWidth
        // return 150
    }
}

Delegate

class ViewController: UIViewController, HTagViewDelegate, HTagViewDataSource {
	// .
	// .
	// .

    // MARK: - HTagViewDelegate
    func tagView(_ tagView: HTagView, tagSelectionDidChange selectedIndices: [Int]) {
        print("tag with indices \(selectedIndices) are selected")
    }
    func tagView(_ tagView: HTagView, didCancelTagAtIndex index: Int) {
        print("tag with index: '\(index)' has to be removed from tagView")
        data.remove(at: index)
        tagView.reloadData()
    }
}

Manually select/deselect tags

tagView.selectTagAtIndex(6)
tagView.deselectTagAtIndex(3)

Author

Hao

License

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

htagview's People

Watchers

Actiwerks avatar James Cloos avatar

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.