From a7e9039346cfcea12bf7020075a76fe70b4f1e83 Mon Sep 17 00:00:00 2001 From: heerucan Date: Thu, 7 Oct 2021 21:20:22 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8[FEAT]=20=EB=8F=84=EC=A0=84=EA=B3=BC?= =?UTF-8?q?=EC=A0=9C1=20=EB=B2=84=ED=8A=BC=20=ED=99=9C=EC=84=B1=ED=99=94?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84(#2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Resource/Support/SceneDelegate.swift | 3 +- .../Source/View Controller/LoginVC.swift | 16 +++++ .../Source/View Controller/SignUpVC.swift | 72 ++++++++++++++----- 3 files changed, 72 insertions(+), 19 deletions(-) diff --git a/Sopt29th-Assignment/Sopt29th-Assignment/Resource/Support/SceneDelegate.swift b/Sopt29th-Assignment/Sopt29th-Assignment/Resource/Support/SceneDelegate.swift index 141cf77..cb830c3 100644 --- a/Sopt29th-Assignment/Sopt29th-Assignment/Resource/Support/SceneDelegate.swift +++ b/Sopt29th-Assignment/Sopt29th-Assignment/Resource/Support/SceneDelegate.swift @@ -16,7 +16,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { guard let windowScene = (scene as? UIWindowScene) else { return } window = UIWindow(frame: windowScene.coordinateSpace.bounds) window?.windowScene = windowScene - window?.rootViewController = SignUpVC() + window?.rootViewController = LoginVC() + window?.backgroundColor = .white window?.makeKeyAndVisible() } diff --git a/Sopt29th-Assignment/Sopt29th-Assignment/Source/View Controller/LoginVC.swift b/Sopt29th-Assignment/Sopt29th-Assignment/Source/View Controller/LoginVC.swift index e061cd8..f5f5b4e 100644 --- a/Sopt29th-Assignment/Sopt29th-Assignment/Source/View Controller/LoginVC.swift +++ b/Sopt29th-Assignment/Sopt29th-Assignment/Source/View Controller/LoginVC.swift @@ -75,6 +75,7 @@ class LoginVC: UIViewController { super.viewDidLoad() configUI() setupAutoLayout() + setupTextField() } // MARK: - Custom Method @@ -125,7 +126,14 @@ class LoginVC: UIViewController { } } + func setupTextField() { + nameTextField.delegate = self + emailTextField.delegate = self + pwTextField.delegate = self + } + // MARK: - @objc + @objc func touchUpSignUpButton(_ sender: UIButton) { } @@ -135,3 +143,11 @@ class LoginVC: UIViewController { } } +// MARK: - UITextFieldDelegate +extension LoginVC: UITextFieldDelegate { + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + pwTextField.resignFirstResponder() + return true + } +} + diff --git a/Sopt29th-Assignment/Sopt29th-Assignment/Source/View Controller/SignUpVC.swift b/Sopt29th-Assignment/Sopt29th-Assignment/Source/View Controller/SignUpVC.swift index 7ad6650..38a58b2 100644 --- a/Sopt29th-Assignment/Sopt29th-Assignment/Source/View Controller/SignUpVC.swift +++ b/Sopt29th-Assignment/Sopt29th-Assignment/Source/View Controller/SignUpVC.swift @@ -36,20 +36,24 @@ class SignUpVC: UIViewController { let nameTextField = UITextField().then { $0.setTextField(placeholder: "이름을 입력해주세요", secure: false) + $0.addTarget(self, action: #selector(textFieldDidChange(textField:)), for: .editingChanged) + } let emailTextField = UITextField().then { $0.setTextField(placeholder: "이메일 또는 휴대전화", secure: false) + $0.addTarget(self, action: #selector(textFieldDidChange(textField:)), for: .editingChanged) } let pwTextField = UITextField().then { $0.setTextField(placeholder: "비밀번호 입력", secure: true) + $0.addTarget(self, action: #selector(textFieldDidChange(textField:)), for: .editingChanged) } - var config = UIButton.Configuration.plain() + var configShow = UIButton.Configuration.plain() - lazy var showPWButton = UIButton(configuration: config, primaryAction: nil).then { - $0.addTarget(self, action: #selector(touchUpShowPWButton(_:)), for: .touchUpInside) + lazy var showButton = UIButton(configuration: configShow, primaryAction: nil).then { + $0.addTarget(self, action: #selector(touchUpShowButton(_:)), for: .touchUpInside) $0.configurationUpdateHandler = { btn in var config = btn.configuration config?.image = btn.isSelected ? UIImage(systemName: "checkmark.square.fill") : UIImage(systemName: "square") @@ -58,10 +62,11 @@ class SignUpVC: UIViewController { } lazy var signUpButton = UIButton().then { + $0.isUserInteractionEnabled = false $0.setTitle("다음", for: .normal) $0.setTitleColor(.white, for: .normal) $0.titleLabel?.font = .boldSystemFont(ofSize: 18) - $0.backgroundColor = .mainBlue + $0.backgroundColor = .lightGray $0.layer.cornerRadius = 10 $0.addTarget(self, action: #selector(touchUpSignUpButton(_:)), for: .touchUpInside) } @@ -69,25 +74,24 @@ class SignUpVC: UIViewController { // MARK: - Lifecycle override func viewDidLoad() { super.viewDidLoad() - configUI() + setupButtonConfig() setupAutoLayout() + setupTextField() } // MARK: - Custom Method - func configUI() { - view.backgroundColor = .white - - // iOS15에서 나온 새로운 기능 - config.imagePlacement = .leading - config.imagePadding = 10 - config.title = "비밀번호 표시" - config.baseForegroundColor = .black - config.baseBackgroundColor = .clear + // iOS15에서 나온 새로운 기능 + func setupButtonConfig() { + configShow.title = "비밀번호 표시" + configShow.baseForegroundColor = .black + configShow.baseBackgroundColor = .clear + configShow.imagePlacement = .leading + configShow.imagePadding = 10 } - + func setupAutoLayout() { view.addSubviews([logoLabel, signUpLabel, fieldStackView, - showPWButton, signUpButton]) + showButton, signUpButton]) logoLabel.snp.makeConstraints { make in make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).inset(20) @@ -109,7 +113,7 @@ class SignUpVC: UIViewController { make.centerX.equalToSuperview() } - showPWButton.snp.makeConstraints { make in + showButton.snp.makeConstraints { make in make.top.equalTo(fieldStackView.snp.bottom).offset(10) make.leading.equalToSuperview().inset(20) } @@ -122,12 +126,37 @@ class SignUpVC: UIViewController { } } + func setupTextField() { + nameTextField.delegate = self + emailTextField.delegate = self + pwTextField.delegate = self + } + // MARK: - @objc + @objc func textFieldDidChange(textField: UITextField){ + guard let name = nameTextField.text, + let email = emailTextField.text, + let pw = pwTextField.text else { + return + } + + if name.isEmpty || email.isEmpty || pw.isEmpty { + signUpButton.isUserInteractionEnabled = false + signUpButton.backgroundColor = .lightGray + print("비활성화") + + } else { + signUpButton.isUserInteractionEnabled = true + signUpButton.backgroundColor = .mainBlue + print("활성화") + } + } + @objc func touchUpSignUpButton(_ sender: UIButton) { } - @objc func touchUpShowPWButton(_ sender: UIButton) { + @objc func touchUpShowButton(_ sender: UIButton) { sender.isSelected = !sender.isSelected if sender.isSelected { pwTextField.isSecureTextEntry = false @@ -137,3 +166,10 @@ class SignUpVC: UIViewController { } } +// MARK: - UITextFieldDelegate +extension SignUpVC: UITextFieldDelegate { + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + pwTextField.resignFirstResponder() + return true + } +}