ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • #17. 텍스트필드(TextField, SecureField)
    SwiftUI 앱만들기 2022. 7. 11. 12:29

    #1. ContentView

     

    import SwiftUI

     

    struct ContentView: View {

        

        @State private var userName : String = ""

        @State private var password : String = ""

        

        var body: some View {

            VStack(spacing:10) {

                HStack {

                    TextField("사용자 이름", text: $userName)

                        .textFieldStyle(RoundedBorderTextFieldStyle())

                        .autocapitalization(.none)// 대문자로 시작안하기

                        .disableAutocorrection(.none) //입력 자동 수정하기 안하기

                        

                    

                    Button(action: {

                        self.userName = ""

                    }){

                        if(self.userName.count > 0){

                            Image(systemName: "multiply.circle.fill")

                                .font(.system(size: 20))

                                .foregroundColor(.secondary) //gray color

                            

                        }

                        

     

                    }

                    

                } .padding(.horizontal)

                

                HStack {

                    SecureField("비밀번호", text: $password)

                        .textFieldStyle(RoundedBorderTextFieldStyle())

                    

                    if(self.password.count > 0 ){

                        Button(action: {

                            self.password = ""

                        }){

                            Image(systemName: "multiply.circle.fill")

                                .font(.system(size: 20))

                                .foregroundColor(.secondary) //gray color

                            

                        }

                    }

                }

                .padding(.horizontal)

                

                

                

                Text("비밀번호 : \(self.password)")

                

            } .padding()

            

        }

    }

     

    struct ContentView_Previews: PreviewProvider {

        static var previews: some View {

            ContentView()

        }

    }

     

     

     


    출처: https://youtu.be/l0X4j_yMT9U

     

    'SwiftUI 앱만들기' 카테고리의 다른 글

    #19. 피커뷰(PickerView)  (0) 2022.07.11
    #18. 토스트, 팝업(Toast, Popup)  (0) 2022.07.11
    #16. 버튼 스타일(Button Style)  (0) 2022.07.11
    #15. 로또앱 만들기(QR Code)  (0) 2022.07.08
    #14. 커스텀 탭뷰(CustomTabView)  (0) 2022.07.08

    댓글

Designed by Tistory.