Skip to content

Instantly share code, notes, and snippets.

@tgnivekucn
Created March 16, 2023 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgnivekucn/20aaf0658be90c0ca22d521a3f7e61d0 to your computer and use it in GitHub Desktop.
Save tgnivekucn/20aaf0658be90c0ca22d521a3f7e61d0 to your computer and use it in GitHub Desktop.
SwiftUI login page generated by bing chatGPT
import SwiftUI
struct LoginView: View {
@State private var username = ""
@State private var password = ""
var body: some View {
VStack {
Image("logo")
.resizable()
.frame(width: 300, height: 300)
.padding(.top, 20)
TextField("Username", text: $username)
.padding()
.border(Color.gray, width: 1)
.padding(.horizontal, 20)
SecureField("Password", text: $password)
.padding()
.border(Color.gray, width: 1)
.padding(.horizontal, 20)
Button(action: login) {
Text("Login")
.foregroundColor(.white)
.padding()
.background(Color.blue)
.cornerRadius(10)
}
.padding(.horizontal, 20)
}
Spacer()
}
// Adjust the bottom padding according to the device
// For example, if the device has a safe area inset of 34 points at the bottom,
// then the bottom padding should be 100 - 34 = 66
// You can use GeometryReader to get the safe area insets of the device
// https://developer.apple.com/documentation/swiftui/geometryreader
// Alternatively, you can use a library like https://github.com/nalexn/ViewInspector
// to get the exact frame of each view and calculate the padding accordingly
// For simplicity, I will just use a fixed value of 100 here
.padding(.bottom, 100)
}
func login() {
// Your login logic here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment