Latest 3.0.1
Homepage https://github.com/popodidi/HTagView
License MIT
Platforms ios 9.0
Frameworks UIKit
Authors

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.

Latest podspec

{
    "name": "HTagView",
    "version": "3.0.1",
    "summary": "A customized tag view sublassing UIView",
    "description": "A customized tag view sublassing UIView where tag could be either with cancel button or seletable.",
    "homepage": "https://github.com/popodidi/HTagView",
    "license": "MIT",
    "authors": {
        "Hao": "[email protected]"
    },
    "source": {
        "git": "https://github.com/popodidi/HTagView.git",
        "tag": "3.0.1"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "HTagView/Classes/**/*",
    "resources": [
        "HTagView/Assets/*.{xcassets,png,jpeg,jpg,storyboard,xib}"
    ],
    "frameworks": "UIKit",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This