IOS/SwiftUI

(SwiftUI)13.TextField

프린이0218 2021. 4. 28. 16:18
//
//  ContentView.swift
//  TextInput_swiftui
//
//  Created by devdepot on 2021/04/28.
//

import SwiftUI

struct ContentView: View {
    
    @State private var username: String = ""
    @State private var password: String = ""
    
    var body: some View {
        
        VStack{
            HStack{
                TextField("사용자 이름",text:$username)
                    .autocapitalization(.none)  //대문자금지
                    .disableAutocorrection(true)    //자동완성 금지
                    .textFieldStyle(RoundedBorderTextFieldStyle())
                Button(action: {
                    self.username = ""
                }, label: {
                    if(self.username.count > 0 ){
                        Image(systemName: "multiply.circle.fill")
                            .foregroundColor(Color.secondary)
                    }
                  
                })
            }
            HStack{
                SecureField("비밀번호",text:$password)
                    .autocapitalization(.none)  //대문자금지
                    .disableAutocorrection(true)    //자동완성 금지
                    .textFieldStyle(RoundedBorderTextFieldStyle())
                Button(action: {
                    self.password = ""
                }, label: {
                    Image(systemName: "multiply.circle.fill")
                        .foregroundColor(Color.secondary)
                })
            }
           
           
            Text("입력한 비번 -> \(password)")
        }.padding(.horizontal,50)
        
       
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}