Skip to content

A SwiftUI horizontal tag menu, with single and multiple selection options, totally customizable

License

Notifications You must be signed in to change notification settings

lucianobohrer/TagMenu

Repository files navigation

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 = TagMenuView<String>(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 = TagMenuView<String>(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.

About

A SwiftUI horizontal tag menu, with single and multiple selection options, totally customizable

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published