Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

앱 최초 실행 로직 (Layout X) #43

Merged
merged 6 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
guard let windowScene = (scene as? UIWindowScene) else { return }

window = UIWindow(windowScene: windowScene)
window?.rootViewController = HomeViewController()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3
혹시 여기 개행 들어가있나용 ?? 있다면 없애도 좋을 거 같습니다 !

let initController: UIViewController
Kyxxn marked this conversation as resolved.
Show resolved Hide resolved
if UserDefaults.standard.object(forKey: "houseName") == nil {
initController = RegisterViewController()
} else {
initController = HomeViewController()
}

let navigationController = UINavigationController(rootViewController: initController)
yuncheol-AHN marked this conversation as resolved.
Show resolved Hide resolved
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
}
}
yuncheol-AHN marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import UIKit

public final class RegisterViewController: UIViewController {
private static let registerButtonFontSize: CGFloat = 12
private static let registerTextFieldFontSize: CGFloat = 24
private let registerTextField: UITextField = {
let registerFont = UIFont.ownglyphBerry(size: registerButtonFontSize)

let textField = UITextField()
textField.font = registerFont
textField.borderStyle = .roundedRect

var attributedText = AttributedString(stringLiteral: "기록소")
attributedText.font = registerFont
textField.attributedPlaceholder = NSAttributedString(attributedText)

return textField
}()
private let registerButton: UIButton = {
let registerButton = UIButton()
yuncheol-AHN marked this conversation as resolved.
Show resolved Hide resolved

var attributedString = AttributedString(stringLiteral: "다음")
attributedString.font = UIFont.ownglyphBerry(size: registerButtonFontSize)

registerButton.setAttributedTitle(NSAttributedString(attributedString), for: .normal)

registerButton.titleLabel?.textColor = #colorLiteral(red: 0.1843137255, green: 0.1843137255, blue: 0.1843137255, alpha: 1)
registerButton.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
registerButton.layer.borderColor = #colorLiteral(red: 0.7019607843, green: 0.1490196078, blue: 0.1176470588, alpha: 1)
yuncheol-AHN marked this conversation as resolved.
Show resolved Hide resolved
registerButton.layer.borderWidth = 1
registerButton.layer.cornerRadius = registerButtonFontSize
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3. (혹시 또 구현하고 계실까봐 말씀드립니다...) 배경 넣는 로직 따로 구현해 두었습니다! 나중에 UIView extension으로 embededInDefaultBackground 사용해주시면 될 것같아요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정현님 테스트 해보았는데, 제꺼 버튼 높이가 24인데 embededInDefaultBackground의 radius가 17로 24/2 보다 커서 테두리가 이질감이 조금 생기네요! 다른 곳에서 배경이 필요하면 적용시켜볼게요 !!


return registerButton
}()

public override func viewDidLoad() {
super.viewDidLoad()

setup()
configureAddSubView()
configureConstraints()
}

private func setup() {
view.backgroundColor = .baseBackground
addTouchEventToRegisterButton(registerButton)
}

private func configureAddSubView() {
view.addSubview(registerTextField)
yuncheol-AHN marked this conversation as resolved.
Show resolved Hide resolved
view.addSubview(registerButton)
}

private func configureConstraints() {
registerTextField.setHeight(RegisterViewController.registerTextFieldFontSize)
registerTextField.setWidth(RegisterViewController.registerTextFieldFontSize * 8)
registerTextField.setCenter(view: view)

registerButton.setHeight(RegisterViewController.registerButtonFontSize * 2)
registerButton.setWidth(RegisterViewController.registerButtonFontSize * 4)
registerButton.setTop(anchor: registerTextField.bottomAnchor, constant: 6)
registerButton.setLeading(anchor: registerTextField.trailingAnchor, constant: -6)
}

private func addTouchEventToRegisterButton(_ button: UIButton) {
let uiAction = UIAction { [weak self] _ in
// TODO: - 저장소 중복 체크

Check warning on line 67 in MemorialHouse/MHPresentation/MHPresentation/Source/Register/RegisterViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (- 저장소 중복 체크) (todo)

Check warning on line 67 in MemorialHouse/MHPresentation/MHPresentation/Source/Register/RegisterViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (- 저장소 중복 체크) (todo)

guard let houseName = self?.registerTextField.text, !houseName.isEmpty else {
self?.showAlert()
yuncheol-AHN marked this conversation as resolved.
Show resolved Hide resolved
return
}

let userDefaults = UserDefaults.standard

userDefaults.set(houseName, forKey: "houseName")
yuncheol-AHN marked this conversation as resolved.
Show resolved Hide resolved

self?.navigationController?.pushViewController(HomeViewController(), animated: false)
self?.navigationController?.viewControllers.removeFirst() // inactive back to register view
}

button.addAction(uiAction, for: .touchUpInside)
}

private func showAlert() {
let alertController = UIAlertController(title: "기록소 이름을 입력해주세요.", message: nil, preferredStyle: .alert)
let alertAction = UIAlertAction(title: "확인", style: .default)

alertController.addAction(alertAction)

present(alertController, animated: true, completion: nil)
}
}
Loading