Skip to content

Show picker from bottom with SwiftUI

   

It is a way to show picker from bottom with SwiftUI. Picker shows from bottom like a modal.

PickerFromBottom

Importing an image into SwiftUI using UIImagePickerController

import SwiftUI
struct ContentView: View {
@State private var year = 2020
@State private var isShowingPicker = false
var body: some View {
ZStack {
Button(action: {
self.isShowingPicker.toggle()
}) {
Text("Year: \(self.year)")
.padding()
}
NumberPicker(selection: self.$year, isShowing: self.$isShowingPicker)
.animation(.linear)
.offset(y: self.isShowingPicker ? 0 : UIScreen.main.bounds.height)
}
}
}
struct NumberPicker: View {
@Binding var selection: Int
@Binding var isShowing: Bool
var body: some View {
VStack {
Spacer()
Button(action: {
self.isShowing = false
}) {
HStack {
Spacer()
Text("Close")
.padding(.horizontal, 16)
}
}
Picker(selection: $selection, label: Text("")) {
ForEach((1900..<2100), id: \.self) {
Text("\($0)")
.tag($0)
}
}
.frame(width: 200)
.labelsHidden()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

  1. Create a sequential numbered array in Swift
  2. Using UIImagePickerController with SwiftUI
  3. Do not change the color of the Image in the Button with SwiftUI
  4. I tried all the ModalPresentationStyle of iOS 13
  5. Detect video end with Swift
  6. Play videos with Swift
  7. Display the side menu (hamburger menu) in SwiftUI with SwiftUI.