To run the example project, clone the repo, and run pod install
from the Example directory first.
ViewModel generic type needs to conform to Displayable
protocol that is responsible to represent the string shown in the tag view.
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)
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)
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)
}
Set TagMenuSettings
custom parameters
let view = TagMenu<String>(viewModel: vm,
tagSettings: TagMenuSettings(highlightColor: .systemRed,
regularColor: .gray,
backgroundColor: .white,
cornerRadius: 8,
borderSize: 1))
File > Swift Packages > Add Package Dependency: https://github.com/lucianobohrer/TagMenu
Add a dependency in your your Package.swift
.package(url: "https://github.com/lucianobohrer/TagMenu.git", from: "1.0.0"),
TagMenu is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'TagMenu'
TagMenu is available under the MIT license. See the LICENSE file for more info.