[SwiftUI] Form

RudinP·2025년 6월 30일
0

Study

목록 보기
300/325

값을 입력하는 화면
스크롤도 자동으로 처리됨

struct Form: View {
	@State private var email = ""
    @State private var password = ""
    @State private var address = ""
    @State private var age = 0
    @State private var receiveEmail = false
	
    var body: some View {
    	Form {
        	TextField("Email", text: $email)
            SecureField("Password", text: $password)
            TextField("Address", text: $aaddress)
            Stepper("Age", value: $age)
            Toggle(isOn: $receiveEmail, label : { Text("Receive Email") })
            Button("확인") {
            
            }
            .padding()
            .frame(maxWidth: .infinity)
        }
    }
}

구역을 분리하고 싶다면 Section으로 나누면 된다.

struct Form: View {
	@State private var email = ""
    @State private var password = ""
    @State private var address = ""
    @State private var age = 0
    @State private var receiveEmail = false
	
    var body: some View {
    	Form {
        	Section{
        		TextField("Email", text: $email)
            	SecureField("Password", text: $password)
            	TextField("Address", text: $aaddress)
            }
            
            Stepper("Age", value: $age)
            Toggle(isOn: $receiveEmail, label : { Text("Receive Email") })
            Button("확인") {
            
            }
            .padding()
            .frame(maxWidth: .infinity)
        }
    }
}
profile
iOS 개발자가 되기 위한 스터디룸...

0개의 댓글