Git Product home page Git Product logo

tagmenu's Introduction

TagMenu

Build Status Version License Platform

Example

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

Usage

Generic Elements

ViewModel generic type needs to conform to Displayable protocol that is responsible to represent the string shown in the tag view.

Single Selection

let viewModel = TagMenuViewModel<String>(items: [
    SelectableListItem(value: "Item 1", selected: true),
    SelectableListItem(value: "Item 2"),
    SelectableListItem(value: "Item 3"),
    SelectableListItem(value: "Item 4")
],
title: "",
selection: .single)

let view = TagMenu(viewModel: viewModel)

Multiple Selection

let viewModel = TagMenuViewModel<String>(items: [
    SelectableListItem(value: "Item 1"),
    SelectableListItem(value: "Item 2"),
    SelectableListItem(value: "Item 3"),
    SelectableListItem(value: "Item 4")
],
title: "Select until 3 items",
selection: .multiple(max: 3))

let view = TagMenu(viewModel: viewModel)

Handling Selection Event

Subscribe the selectedItemsSubject to get the current selected values when a new item is selected/deselected.

var cancellable: Cancellable?

cancellable = viewModel.selectedItemsSubject.sink { (values) in
    print(values)
}

Customizing the view

Set TagMenuSettings custom parameters

let view = TagMenu<String>(viewModel: vm,
                           tagSettings: TagMenuSettings(highlightColor: .systemRed,
                                                        regularColor: .gray,
                                                        backgroundColor: .white,
                                                        cornerRadius: 8,
                                                        borderSize: 1))

Package

For Xcode Projects

File > Swift Packages > Add Package Dependency: https://github.com/lucianobohrer/TagMenu

For Swift Packages

Add a dependency in your your Package.swift

.package(url: "https://github.com/lucianobohrer/TagMenu.git", from: "1.0.0"),

CocoaPods

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

pod 'TagMenu'

Authors

License

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

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.