You can create an EliminationMenu view in Interface Builder or in code.
Create entries
To set up the entries, create an array of instances conforming to EliminationMenuItem and set it to the items property of the menu object.
let menuEntries = [
EliminationMenu.Item(value: "SomeValue", title: "First"),
EliminationMenu.Item(value: "SomeOtherValue", title: "Second"),
EliminationMenu.Item(value: UIImage(named: "filename"), title: "Third"), // You can use values of any kind.
EliminationMenu.Item(value: "...or a view", title: "Fourth"),
"Just a String",
MyCustomType(customProperty: true, someOtherProperty: 5)
]
menu.items = menuEntries
Hint: The default type EliminationMenu.Item can be used to populate the menu. But you can also make your own types conform to EliminationMenuItem and use them directly.
String already conforms to it. So you can use Strings as menu items. See the example project for an overview.
Create Menu
Use the convenience method to create a menu and add it as a subview to your view controllers view.
let menu = EliminationMenu.createMenu(withItems: menuEntries, inView: view, aligned: .topRight, margin: CGPoint(x: 0, y: 20)) { (item) in
print("Selected value: \(item.value)")
}
If you want to use Interface Builder, just add a UIView and pin 2 of its edges (vertical and horizontal). Set EliminationMenu as the views class. Also add a width and a height constraint to supress warnings. Enable “Remove at build time“ on the size constraints. The menu will get an intrinsic size at runtime.
You can also create an instance of EliminationMenu and constrain it yourself in a superview. Be shure to call menu.setup() after all.
EliminationMenu
Some kind of menu that eliminates all values which were not selected.
Installation
Just drag the Folder
Sourcesinto your project.Cocoapods
If you´re using CocoaPods, add this to your Podfile:
Swift Package Manager
To add EliminationMenu to a Swift Package Manager based project, add the following:
to the
dependenciesvalue of yourPackage.swift.Usage
You can create an EliminationMenu view in Interface Builder or in code.
Create entries
To set up the entries, create an array of instances conforming to
EliminationMenuItemand set it to theitemsproperty of the menu object.Hint: The default type
EliminationMenu.Itemcan be used to populate the menu. But you can also make your own types conform toEliminationMenuItemand use them directly.Stringalready conforms to it. So you can use Strings as menu items. See the example project for an overview.Create Menu
Use the convenience method to create a menu and add it as a subview to your view controllers view.
If you want to use Interface Builder, just add a
UIViewand pin 2 of its edges (vertical and horizontal). SetEliminationMenuas the views class. Also add a width and a height constraint to supress warnings. Enable “Remove at build time“ on the size constraints. The menu will get an intrinsic size at runtime.You can also create an instance of
EliminationMenuand constrain it yourself in a superview. Be shure to callmenu.setup()after all.See the example code for a better insight.
Customize
You can customize the properties of your menu like this:
Be shure to call
menu.setup()to apply your changes. See the documentation for more ways to customize.License
EliminationMenuis available under the MIT license. See the LICENSE file for more info.