hta

HTagView

A customized tag view UI element for iOS development

Showing:

Popularity

Downloads/wk

0

GitHub Stars

61

Maintenance

Last Commit

2yrs ago

Contributors

5

Package

Dependencies

0

License

MIT

Categories

Readme

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 VersionHTagView Version
Swift 2.32.0.x
Swift 3.02.1.x
Swift 3.03.x
Swift 5.04.x

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
    tagView.tagElevation = 40
}

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.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100