Skip to content

SwiftUI view modifier to move content above the keyboard.

License

Notifications You must be signed in to change notification settings

igruenig/keyboardOffset

Repository files navigation

Keyboard Offset

Installation

Add this Swift package in Xcode using its GitHub repository url. (File > Swift Packages > Add Package Dependency...)

Usage

import KeyboardOffset // 1. Import library

struct ContentView: View {
  
  @State private var firstName = ""
  @State private var lastName = ""
  @State private var street = ""
  @State private var city = ""
  
  var body: some View {
    NavigationView {
      Form {
        HStack {
          Spacer()
          Image(systemName: "cart.fill")
            .resizable()
            .aspectRatio(contentMode: ContentMode.fit)
            .frame(height: 200)
            .padding()
          Spacer()
        }
        
        
        Section {
          TextField("First Name", text: $firstName)
          TextField("Last Name", text: $lastName)
        }
        
        Section {
          TextField("Street", text: $street)
          TextField("City", text: $city)
        }
        
      }
      .navigationBarTitle(Text("Checkout"))
      .keyboardOffset() // 2. Add view modifier
    }
  }
}

License

MIT

About

SwiftUI view modifier to move content above the keyboard.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages