Reputation: 3518
I've been using a UIPickerView, but it takes up way too much room on the screen, I don't understand why it needs to show other available options and not just the one selected.
Is there any standard widget that could be sensibly used to show one value, but then, when clicked, present a list of arbitrary length to be selected from to change that value? Ie a dropdown box or similar?
Many thanks!
EDIT: I think I'm going to go with a UIStepper. It's a bit more clunky but it's actually ok for my use case since I'm selecting numbers.
Upvotes: 0
Views: 307
Reputation: 5643
There is no dropdown menu in IOS. But you can create a tableView acting as dropdown box according to your needs.
Writing all codes is will be messy due to constraint logics but these lines of code hope will be helpful and hope you will get to point.
var dropView = dropDownView()
var height = NSLayoutConstraint()
var isOpen = false
// control with protocol your state
protocol DropDownProtocol {
func DropDownPressed(string : String)
}
class DropDownButon: UIButton, DropDownProtocol {
func dropDownPressed(string: String) {
self.setTitle(string, for: .normal)
self.dismissDropDown()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if isOpen == false {
isOpen = true
// animate your dropView for opening
} else {
isOpen = false
// animate your dropView for closing
}
}
Upvotes: 1