From d53296166f16da6c96ad03a34694ac45ea917f5c Mon Sep 17 00:00:00 2001 From: Melt Date: Sat, 29 Apr 2023 07:04:16 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20=EB=A7=88=EC=9D=B4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20UI=EA=B5=AC=ED=98=84=20#8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SOPTving/SOPTving/Domain/Entity/Setting.swift | 33 ++++++ .../MainScene/View/MyPageProfileView.swift | 5 +- .../View/MyPageSettingFooterView.swift | 85 ++++++++++++++ .../View/MyPageSettingTableViewCell.swift | 78 +++++++++++++ .../MainScene/ViewController/MyPageVC.swift | 105 +++++++++++++++++- .../MainScene/ViewModel/MyPageViewModel.swift | 5 +- .../Utility/Builder/ButtonBuilder.swift | 1 + .../SOPTving/Utility/Extension/UIView+.swift | 6 + 8 files changed, 309 insertions(+), 9 deletions(-) create mode 100644 SOPTving/SOPTving/Domain/Entity/Setting.swift create mode 100644 SOPTving/SOPTving/Presentation/MainScene/View/MyPageSettingFooterView.swift create mode 100644 SOPTving/SOPTving/Presentation/MainScene/View/MyPageSettingTableViewCell.swift diff --git a/SOPTving/SOPTving/Domain/Entity/Setting.swift b/SOPTving/SOPTving/Domain/Entity/Setting.swift new file mode 100644 index 0000000..32e1c75 --- /dev/null +++ b/SOPTving/SOPTving/Domain/Entity/Setting.swift @@ -0,0 +1,33 @@ +// +// Setting.swift +// SOPTving +// +// Created by 장석우 on 2023/04/29. +// + +import Foundation + + + +struct MyPageSetting { + + enum UserSetting: String, CaseIterable { + case memberShip = "이용권" + case inquiryDetails = "1:1 문의내역" + case reservation = "예약알림" + case changeUserInfo = "회원정보수정" + case acceptMessages = "프로모션정보수신동의" + } + + enum AppSetting: String, CaseIterable { + case notice = "공지사항" + case event = "이벤트" + case serviceCenter = "고객센터" + case more = "티빙 알아보기" + } + + var userSetting = UserSetting.allCases.map { $0.rawValue } + var appSetting = AppSetting.allCases.map { $0.rawValue } +} + + diff --git a/SOPTving/SOPTving/Presentation/MainScene/View/MyPageProfileView.swift b/SOPTving/SOPTving/Presentation/MainScene/View/MyPageProfileView.swift index caf5376..7d6c935 100644 --- a/SOPTving/SOPTving/Presentation/MainScene/View/MyPageProfileView.swift +++ b/SOPTving/SOPTving/Presentation/MainScene/View/MyPageProfileView.swift @@ -180,11 +180,11 @@ extension MyPageProfileView { } nameButton.snp.makeConstraints { - $0.centerY.equalToSuperview() + $0.centerY.equalTo(profileImageView) $0.leading.equalTo(profileImageView.snp.trailing) } profileChangeButton.snp.makeConstraints { - $0.centerY.equalToSuperview() + $0.centerY.equalTo(profileImageView) $0.trailing.equalToSuperview() $0.height.equalTo(30) $0.width.equalTo(80) @@ -194,6 +194,7 @@ extension MyPageProfileView { $0.top.equalTo(profileImageView.snp.bottom).offset(20) $0.leading.trailing.equalToSuperview() $0.height.equalTo(100) + $0.bottom.equalToSuperview() } darkStackView.snp.makeConstraints { diff --git a/SOPTving/SOPTving/Presentation/MainScene/View/MyPageSettingFooterView.swift b/SOPTving/SOPTving/Presentation/MainScene/View/MyPageSettingFooterView.swift new file mode 100644 index 0000000..85794a4 --- /dev/null +++ b/SOPTving/SOPTving/Presentation/MainScene/View/MyPageSettingFooterView.swift @@ -0,0 +1,85 @@ +// +// MyPageSettingFooterView.swift +// SOPTving +// +// Created by 장석우 on 2023/04/29. +// + +import UIKit + +final class MyPageSettingFooterView: UIView { + + //MARK: - Properties + + private let isLastSection: Bool + + //MARK: - UI Components + + private let seperatorView: UIView = { + let view = UIView() + view.backgroundColor = .tvingDarkGray + return view + }() + + private let logoutButton : UIButton = { + let button = UIButton() + button.setBorder(width: 1, color: .tvingDarkGray) + button.makeCornerRound(ratio: 20) + button.setTitle("로그아웃", for: .normal) + button.setTitleColor(.tvingLightGray, for: .normal) + button.titleLabel?.font = .tvingMedium(ofSize: 14) + return button + }() + + private lazy var vStackView: UIStackView = { + let stackView = UIStackView(arrangedSubviews: [seperatorView,logoutButton]) + stackView.axis = .vertical + stackView.alignment = .center + return stackView + }() + + //MARK: - Life Cycle + + + init(isLastSection: Bool) { + self.isLastSection = isLastSection + super.init(frame: .zero) + + style() + hierarchy() + layout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + //MARK: - Custom Method + + private func style() { + seperatorView.isHidden = isLastSection + logoutButton.isHidden = !isLastSection + } + + private func hierarchy() { + self.addSubviews(vStackView) + } + + private func layout() { + + vStackView.snp.makeConstraints { + $0.top.bottom.equalToSuperview().inset(20) + $0.leading.trailing.equalToSuperview() + } + + seperatorView.snp.makeConstraints { + $0.width.equalToSuperview().inset(10) + $0.height.equalTo(1) + } + + logoutButton.snp.makeConstraints { + $0.width.equalToSuperview() + $0.height.equalTo(54) + } + } +} diff --git a/SOPTving/SOPTving/Presentation/MainScene/View/MyPageSettingTableViewCell.swift b/SOPTving/SOPTving/Presentation/MainScene/View/MyPageSettingTableViewCell.swift new file mode 100644 index 0000000..e622a47 --- /dev/null +++ b/SOPTving/SOPTving/Presentation/MainScene/View/MyPageSettingTableViewCell.swift @@ -0,0 +1,78 @@ +// +// MyPageSettingTableViewCell.swift +// SOPTving +// +// Created by 장석우 on 2023/04/29. +// + +import UIKit + +final class MyPageSettingTableViewCell: UITableViewCell { + + //MARK: - Properties + + + //MARK: - UI Components + + private let titleLabel: UILabel = { + let label = UILabel() + label.textColor = .tvingLightGray + label.font = .tvingMedium(ofSize: 16) + return label + }() + + private let rightImageView: UIImageView = { + let view = UIImageView() + view.image = UIImage(systemName: "chevron.right") + view.contentMode = .scaleAspectFit + view.tintColor = .tvingLightGray + return view + }() + + //MARK: - Life Cycle + + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + setUI() + hierarchy() + layout() + + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + //MARK: - Custom Method + + func dataBind(_ text: String) { + titleLabel.text = text + } +} + +extension MyPageSettingTableViewCell { + + func setUI() { + contentView.backgroundColor = .black + } + + func hierarchy() { + contentView.addSubviews(titleLabel, rightImageView) + } + + func layout() { + titleLabel.snp.makeConstraints { + $0.centerY.equalToSuperview() + $0.leading.equalToSuperview().offset(10) + } + + rightImageView.snp.makeConstraints { + $0.centerY.equalToSuperview() + $0.trailing.equalToSuperview().offset(-5) + $0.size.equalTo(20) + } + } + +} diff --git a/SOPTving/SOPTving/Presentation/MainScene/ViewController/MyPageVC.swift b/SOPTving/SOPTving/Presentation/MainScene/ViewController/MyPageVC.swift index 874efc1..c3364e8 100644 --- a/SOPTving/SOPTving/Presentation/MainScene/ViewController/MyPageVC.swift +++ b/SOPTving/SOPTving/Presentation/MainScene/ViewController/MyPageVC.swift @@ -13,6 +13,7 @@ final class MyPageVC: UIViewController { //MARK: - Properties + private var myPageSettingData = MyPageSetting() private let viewModel: MyPageViewModel //MARK: - UI Components @@ -45,6 +46,16 @@ final class MyPageVC: UIViewController { private let profileView = MyPageProfileView() + private let tableView : UITableView = { + let tableView = UITableView() + tableView.backgroundColor = .clear + tableView.separatorStyle = .none + tableView.isScrollEnabled = false + tableView.register(MyPageSettingTableViewCell.self, + forCellReuseIdentifier: MyPageSettingTableViewCell.className) + return tableView + }() + //MARK: - Life Cycle @@ -60,7 +71,6 @@ final class MyPageVC: UIViewController { delegate() - style() hierarchy() layout() @@ -71,6 +81,13 @@ final class MyPageVC: UIViewController { } + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + tableView.snp.updateConstraints { + $0.height.equalTo(tableView.contentSize.height) + } + } + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } @@ -81,7 +98,8 @@ final class MyPageVC: UIViewController { extension MyPageVC { private func delegate() { - + tableView.delegate = self + tableView.dataSource = self } private func bind() { @@ -114,7 +132,7 @@ extension MyPageVC { navigationView.addSubview(backButton) scrollView.addSubview(contentView) - contentView.addSubviews(profileView) + contentView.addSubviews(profileView,tableView) } private func layout() { @@ -145,9 +163,86 @@ extension MyPageVC { profileView.snp.makeConstraints { $0.top.equalToSuperview() $0.leading.trailing.equalToSuperview() - $0.height.equalTo(100) - $0.bottom.equalToSuperview() } + + tableView.snp.makeConstraints { + $0.top.equalTo(profileView.snp.bottom).offset(10) + $0.leading.trailing.equalToSuperview() + $0.height.equalTo(tableView.contentSize.height) + $0.bottom.equalToSuperview().offset(-30) + } + + } } +//MARK: - UITableViewDelegate + +extension MyPageVC: UITableViewDelegate { + +} + +extension MyPageVC: UITableViewDataSource { + func numberOfSections(in tableView: UITableView) -> Int { + return 2 + } + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + switch section { + case 0: + return myPageSettingData.userSetting.count + case 1: + return myPageSettingData.appSetting.count + default: + return 0 + } + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + + guard let cell = tableView.dequeueReusableCell(withIdentifier: MyPageSettingTableViewCell.className, for: indexPath) as? MyPageSettingTableViewCell + else { return UITableViewCell()} + + switch indexPath.section { + case 0: + cell.dataBind(myPageSettingData.userSetting[indexPath.row]) + + case 1: + cell.dataBind(myPageSettingData.appSetting[indexPath.row]) + default: + fatalError("\(#function)에서 에러가 발생했습니다.") + } + return cell + } + + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + return 54 + } +} + +extension MyPageVC { + + func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { + switch section { + case 0: + return MyPageSettingFooterView(isLastSection: false).intrinsicContentSize.height + case 1: + return MyPageSettingFooterView(isLastSection: true).intrinsicContentSize.height + default: + return 0 + + } + } + + func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { + + switch section { + case 0: + return MyPageSettingFooterView(isLastSection: false) + case 1: + return MyPageSettingFooterView(isLastSection: true) + default: + return nil + } + } +} diff --git a/SOPTving/SOPTving/Presentation/MainScene/ViewModel/MyPageViewModel.swift b/SOPTving/SOPTving/Presentation/MainScene/ViewModel/MyPageViewModel.swift index 9f58839..13f93c6 100644 --- a/SOPTving/SOPTving/Presentation/MainScene/ViewModel/MyPageViewModel.swift +++ b/SOPTving/SOPTving/Presentation/MainScene/ViewModel/MyPageViewModel.swift @@ -24,6 +24,8 @@ final class DefaultMyPageViewModel: MyPageViewModel { private var profileData: MyProfile + + //MARK: - Output @@ -35,10 +37,9 @@ final class DefaultMyPageViewModel: MyPageViewModel { self.profileData = profileData } - - //MARK: - Private + } //MARK: - Input, Event diff --git a/SOPTving/SOPTving/Utility/Builder/ButtonBuilder.swift b/SOPTving/SOPTving/Utility/Builder/ButtonBuilder.swift index 9dd8570..f7e2b48 100644 --- a/SOPTving/SOPTving/Utility/Builder/ButtonBuilder.swift +++ b/SOPTving/SOPTving/Utility/Builder/ButtonBuilder.swift @@ -20,6 +20,7 @@ protocol ButtonBuildable: ViewBuildable { func setAction(event: UIControl.Event, handler: @escaping UIActionHandler) -> Self + } //MARK: - Builder diff --git a/SOPTving/SOPTving/Utility/Extension/UIView+.swift b/SOPTving/SOPTving/Utility/Extension/UIView+.swift index af3e125..519bc29 100644 --- a/SOPTving/SOPTving/Utility/Extension/UIView+.swift +++ b/SOPTving/SOPTving/Utility/Extension/UIView+.swift @@ -8,6 +8,12 @@ import UIKit extension UIView { + + static var className: String { + get { return String(describing: self)} + } + + func addSubviews(_ views: UIView...) { views.forEach { self.addSubview($0) } }