Skip to content

Morbix/CloudTagView

Repository files navigation

CloudTagView

Version License Platform Swift 4.0 compatible

This Pod helps you to create a simple cloud of tags based on Strings. You can manipulate the text, the padding and you can use the tintColor to modify the tag color. There are two delegates to handle taps in the tag: close icon and tag touch. You can access the example project for more details or contacting me.

Requirements

It requires Xcode 9.0+ and Swift 4.0.

Your project deployment target must be iOS 8.0+

For Swift 2.x support, use version 1.1.0 For Swift 3.x support, use version 2.0.0

Usage

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

Installation

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

pod 'CloudTagView'

Usage

Basic Usage

Just import CloudTagView and create a instance of CloudTagView. Works with Storyboard too

And append instancies of TagView inside the cloud.

import CloudTagView

class ViewController: UIViewController {

    let cloudView = CloudTagView()

    override func viewDidLoad() {
        super.viewDidLoad()

        cloudView.frame = CGRect(x: 0, y: 20, width: view.frame.width, height: 10)
        view.addSubview(cloudView)

        setupTags()
    }

    fileprivate func setupTags() {
        let tags = ["This", "is", "a", "example", "of", "Cloud", "Tag", "View"]

        for tag in tags {
            cloudView.tags.append(TagView(text: tag))
        }
    }
}

Other tags

Normal
let normalTag = TagView(text: "normal tag")
Fat
let fatTag = TagView(text: "fat tag")
fatTag.marginTop = 20
Long
let longTag = TagView(text: "stretched tag")
longTag.marginLeft = 40
Trimmed
let trimmedTag = TagView(text: "Trimmed: This tag is a example of tag with a huge text.")
trimmedTag.maxLength = 15
Without Icon
let withoutIconTag = TagView(text: "tag without dismiss icon")
withoutIconTag.iconImage = nil
Custom Font
let customFontTag = TagView(text: "different font tag")
customFontTag.font = UIFont(name: "Baskerville", size: 12)!
Custom Background Color
let coloredTag = TagView(text: "colored tag")
coloredTag.backgroundColor = UIColor.blue.withAlphaComponent(0.6)
Custom Tint Color
let tintColorTag = TagView(text: "tint color tag")
tintColorTag.tintColor = UIColor.yellow

TagViewDelegate

Dismiss Event
func tagDismissed(_ tag: TagView)
Touch Event
func tagTouched(_ tag: TagView)

Author

Henrique Morbin, [email protected]

License

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