A lightweight single selection view that slides up from bottom of the screen.
- Easy to use
- Sectioned rows
- Auto adjusting selection view height
- Auto displying searchbar based on the number of items. (you can hide/show searbar manually too)
- Gesture control to drag down to dismiss
A list showing cities (rows) of respective states (sections)
SASelectionView works on iOS 9 and higher. It depends on the following Apple frameworks, which should already be included with most Xcode templates:
- Foundation
- UIKit
You can use CocoaPods to install SASelectionView by adding it to your Podfile:
pod 'SASelectionView'
- Download and extraxt zip file.
- Drag and drop Source folder in your project.
- Done!
import SwiftUI
import SASelectionView
struct ContentView: View {
@State private var selectedText = ""
var body: some View {
VStack {
Button(action: {
self.showSelectionView()
}) {
Text("Show List")
}
.padding(EdgeInsets(top: 0, leading: 0, bottom: 12, trailing: 0))
Text(selectedText)
}
}
func showSelectionView() {
var sections = [SectionItem]()
sections.append(SectionItem(title: "Texas", options: ["Dallas", "Houston", "Austin", "San Antonio"]))
sections.append(SectionItem(title: "California", options: ["Los Angeles", "San Francisco", "Sacramento", "San Diago"]))
sections.append(SectionItem(title: "New York", options: ["New York City", "Albany", "Buffalo"]))
sections.append(SectionItem(title: "Florida", options: ["Miami", "Orlando", "Jacksonville", "Key West"], disabledIndices: [3:[1,3]]))
SASelectionView.show(title: "Locations", sections: sections, showSearchBar: true, emptySearchRowTitle: "Item not found. Add this ...", emptyRowHandler: { (notFoundText) in
print("Not found result: \(notFoundText)")
self.selectedText = notFoundText
}) { (section, row, value) in
self.selectedText = "\(value), \(sections[section].title ?? "")"
}
}
}
#if DEBUG
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
If you have feature requests or bug reports, please feel free to help out by sending pull requests or create issues.
This code is distributed under the terms and conditions of the MIT license.