diff --git a/Pinit/Pinit/Views/PinDetail/EmptyGuideView.swift b/Pinit/Pinit/Views/PinDetail/EmptyGuideView.swift deleted file mode 100644 index 50276a9..0000000 --- a/Pinit/Pinit/Views/PinDetail/EmptyGuideView.swift +++ /dev/null @@ -1,76 +0,0 @@ -// -// EmptyGuideView.swift -// Pinit -// -// Created by nelime on 3/17/25. -// - - -// -// EmptyGuideView.swift -// WeeklyProject-MyContentManager -// -// Created by 안정흠 on 3/7/25. -// - -import UIKit - -final class EmptyGuideView: UIView { - private let iconImageView: UIImageView - private let guideTitleLabel: UILabel - private let guideMessage: UILabel - - init(systemImage: UIImage?, title: String, message: String) { - iconImageView = UIImageView(image: systemImage) - guideTitleLabel = UILabel() - guideMessage = UILabel() - - guideTitleLabel.text = title - guideMessage.text = message - super.init(frame: .infinite) - setupViewProperties() - setupLayout() - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - private func setupLayout() { - [iconImageView, guideTitleLabel, guideMessage].forEach { - $0.translatesAutoresizingMaskIntoConstraints = false - addSubview($0) - } - - NSLayoutConstraint.activate([ - iconImageView.heightAnchor.constraint(equalToConstant: 64), - iconImageView.widthAnchor.constraint(equalToConstant: 64), - iconImageView.centerYAnchor.constraint(equalTo: centerYAnchor), - iconImageView.centerXAnchor.constraint(equalTo: centerXAnchor), - - guideTitleLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16), - guideTitleLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16), - guideTitleLabel.topAnchor.constraint(equalTo: iconImageView.bottomAnchor, constant: 16), - - guideMessage.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16), - guideMessage.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16), - guideMessage.topAnchor.constraint(equalTo: guideTitleLabel.bottomAnchor, constant: 16) - ]) - } - - private func setupViewProperties() { - backgroundColor = .secondarySystemBackground - - iconImageView.contentMode = .scaleAspectFit - iconImageView.tintColor = .gray - - guideTitleLabel.font = .preferredFont(forTextStyle: .title1) - guideMessage.font = .preferredFont(forTextStyle: .body) - - [guideTitleLabel, guideMessage].forEach { - $0.textColor = .gray - $0.numberOfLines = 0 - $0.textAlignment = .center - } - } -} \ No newline at end of file diff --git a/Pinit/Pinit/Views/PinDetail/PinDetailHeader.swift b/Pinit/Pinit/Views/PinDetail/PinDetailHeader.swift index 0529812..884dba7 100644 --- a/Pinit/Pinit/Views/PinDetail/PinDetailHeader.swift +++ b/Pinit/Pinit/Views/PinDetail/PinDetailHeader.swift @@ -64,6 +64,7 @@ class PinDetailHeader: UIView { public lazy var pinImageView: UIImageView = { let imageView = UIImageView() imageView.image = UIImage(named: "sampleImg.jpg") + imageView.contentMode = .scaleAspectFit return imageView }() @@ -150,6 +151,3 @@ class PinDetailHeader: UIView { PinDetailHeader() } -#Preview { - PinDetailViewController() -} diff --git a/Pinit/Pinit/Views/PinDetail/PinDetailView.swift b/Pinit/Pinit/Views/PinDetail/PinDetailView.swift index f1ce0be..a1bad80 100644 --- a/Pinit/Pinit/Views/PinDetail/PinDetailView.swift +++ b/Pinit/Pinit/Views/PinDetail/PinDetailView.swift @@ -107,5 +107,5 @@ class PinDetailView: UIView { #Preview { - PinDetailViewController() + PinDetailViewController(PinEntity.sampleData[0]) } diff --git a/Pinit/Pinit/Views/PinDetail/PinDetailViewController.swift b/Pinit/Pinit/Views/PinDetail/PinDetailViewController.swift index 30c9c04..cb9851d 100644 --- a/Pinit/Pinit/Views/PinDetail/PinDetailViewController.swift +++ b/Pinit/Pinit/Views/PinDetail/PinDetailViewController.swift @@ -10,9 +10,24 @@ import UIKit import SnapKit import MapKit -// MARK: - Pin Detail Main View Controller + +// MARK: - Pin Detail Main ViewController final class PinDetailViewController: UIViewController { + private var pinTableView = UITableView(frame: .zero, style: .grouped) + private var pinEntity: PinEntity + + init(_ entity: PinEntity) { + self.pinEntity = entity + + super.init(nibName: nil, bundle: nil) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + // 더미 리뷰 데이터 private lazy var datasource: [ReviewEntity] = [ ReviewEntity(id: UUID(), pinID: UUID(), date: Date(), description: "리뷰1"), @@ -20,7 +35,6 @@ final class PinDetailViewController: UIViewController { ReviewEntity(id: UUID(), pinID: UUID(), date: Date(), description: "리뷰3") ] - public var pinTableView: UITableView! // MARK: - VIewDidLoad override func viewDidLoad() { @@ -37,17 +51,19 @@ final class PinDetailViewController: UIViewController { // 지도 뷰 public lazy var mapView: MKMapView = { let map = MKMapView() + let lat = pinEntity.latitude + let long = pinEntity.longitude - let center = CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194) // San Francisco, CA + let center = CLLocationCoordinate2D(latitude: lat, longitude: long) // San Francisco, CA let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05)) map.setRegion(region, animated: true) map.showsUserLocation = true let annotation = MKPointAnnotation() - annotation.coordinate = CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194) // San Francisco, CA - annotation.title = "San Francisco" - annotation.subtitle = "CA" + annotation.coordinate = CLLocationCoordinate2D(latitude: lat, longitude: long) // San Francisco, CA + annotation.title = pinEntity.title + annotation.subtitle = pinEntity.weather map.addAnnotation(annotation) return map @@ -66,13 +82,9 @@ final class PinDetailViewController: UIViewController { return button }() - @objc func dismissButtonTapped() { - self.dismiss(animated: true, completion: nil) - } - // 리뷰 테이블뷰 설정 private func setupReviewTable() { - pinTableView = UITableView(frame: .zero, style: .grouped) +// pinTableView = UITableView(frame: .zero, style: .grouped) pinTableView.estimatedRowHeight = UITableView.automaticDimension pinTableView.dataSource = self pinTableView.delegate = self @@ -122,12 +134,43 @@ final class PinDetailViewController: UIViewController { $0.top.equalTo(mapView.snp.bottom) $0.bottom.equalTo(reviewPanelContainer.snp.top) } + } +} + + + +// MARK: - objc function +extension PinDetailViewController { + + @objc func dismissButtonTapped() { + self.dismiss(animated: true, completion: nil) + } + + @objc func pinMenuButtonTapped() { + let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) + + let editAction = UIAlertAction(title: "수정", style: .default) { _ in + print("수정") + let vc = PinEditViewController() + vc.modalPresentationStyle = .fullScreen + self.present(vc, animated: true, completion: nil) + } + let deleteAction = UIAlertAction(title: "삭제", style: .destructive) { _ in + print("삭제") + } + let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: nil) + actionSheet.addAction(editAction) + actionSheet.addAction(deleteAction) + actionSheet.addAction(cancelAction) + present(actionSheet, animated: true, completion: nil) } } + + // MARK: - Delegate extension PinDetailViewController: UITableViewDataSource, UITableViewDelegate { @@ -170,28 +213,16 @@ extension PinDetailViewController: UITableViewDataSource, UITableViewDelegate { // viewForHeaderInSection func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let header = PinDetailHeader() + header.pinDate.text = pinEntity.date.koreanDateString() + header.pinTitle.text = pinEntity.title + header.pinImageView.image = pinEntity.mediaPath + header.pinWeather.text = pinEntity.weather + header.pinDescription.text = pinEntity.description header.pinMenuButton.addTarget(self, action: #selector(pinMenuButtonTapped), for: .touchUpInside) return header } - @objc func pinMenuButtonTapped() { - let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) - - let editAction = UIAlertAction(title: "수정", style: .default) { _ in - print("수정") - self.present(PinEditViewController(), animated: true, completion: nil) - } - let deleteAction = UIAlertAction(title: "삭제", style: .destructive) { _ in - print("삭제") - } - let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: nil) - - actionSheet.addAction(editAction) - actionSheet.addAction(deleteAction) - actionSheet.addAction(cancelAction) - - present(actionSheet, animated: true, completion: nil) - } + // estimatedHeightForHeaderInSection func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat { @@ -211,5 +242,5 @@ extension PinDetailViewController: UITableViewDataSource, UITableViewDelegate { #Preview { - PinDetailViewController() + PinDetailViewController(PinEntity.sampleData[0]) } diff --git a/Pinit/Pinit/Views/PinDetail/PinReviewTableViewController.swift b/Pinit/Pinit/Views/PinDetail/PinReviewTableViewController.swift deleted file mode 100644 index dbba4dd..0000000 --- a/Pinit/Pinit/Views/PinDetail/PinReviewTableViewController.swift +++ /dev/null @@ -1,130 +0,0 @@ - - -import UIKit - -class PinReviewTableViewController: UIViewController { - // private let coreData = CoreDataManager() - // private lazy var datasource: [Content] = coreData.fetchContents() - private lazy var datasource: [ReviewEntity] = [ReviewEntity(id: UUID(), pinID: UUID(), date: Date(), description: "it's my life")] - - - public var pinTableView: UITableView! - - - private let emptyView: EmptyGuideView = { - let view = EmptyGuideView( - systemImage: UIImage(systemName: "text.document"), - title: "리뷰가 없습니다.", - message: "오른쪽 위 \"+\" 버튼을 눌러 메모를 추가하세요" - ) - return view - }() - - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view. - self.title = "Memo" - - setupTableView() - setupLayout() - } - - private func setupTableView() { - pinTableView = UITableView() - pinTableView.estimatedRowHeight = UITableView.automaticDimension - pinTableView.dataSource = self - pinTableView.delegate = self - pinTableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") - } - - private func setupLayout() { - view.addSubviews(pinTableView, emptyView) - - pinTableView.snp.makeConstraints { - $0.edges.equalToSuperview() - } - - emptyView.snp.makeConstraints { - $0.edges.equalToSuperview() - } - } -} - - - - -// MARK: - Delegate -extension PinReviewTableViewController: UITableViewDataSource, UITableViewDelegate { - func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - tableView.deselectRow(at: indexPath, animated: false) - } - func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { - let action = UIContextualAction(style: .destructive, title: "삭제") { [weak self] _, _, completion in - if let deleted = self?.datasource.remove(at: indexPath.row).id { - // self?.coreData.deleteContent(id: deleted) - self?.pinTableView.deleteRows(at: [indexPath], with: .automatic) - } - } - return UISwipeActionsConfiguration(actions: [action]) - } - - - - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - if datasource.isEmpty { - tableView.isHidden = true - emptyView.isHidden = false - return 0 - } - else { - tableView.isHidden = false - emptyView.isHidden = true - return datasource.count - } - } - - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - - let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) - - cell.contentView.subviews.forEach { $0.removeFromSuperview() } - - let label = UILabel(frame: cell.contentView.bounds) - label.text = datasource[indexPath.row].description - label.numberOfLines = 0 - label.translatesAutoresizingMaskIntoConstraints = false - cell.contentView.addSubview(label) - NSLayoutConstraint.activate([ - label.leadingAnchor.constraint(equalTo: cell.contentView.leadingAnchor, constant: 16), - label.trailingAnchor.constraint(equalTo: cell.contentView.trailingAnchor, constant: -16), - label.topAnchor.constraint(equalTo: cell.contentView.topAnchor, constant: 8), - label.bottomAnchor.constraint(equalTo: cell.contentView.bottomAnchor, constant: -8) - ]) - - return cell - - } - - func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { - return PinDetailHeader() - } - - func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat { - return 100 - } - - func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { - return UITableView.automaticDimension - } - -} - - - -#Preview { - PinReviewTableViewController() -} - -#Preview { - PinDetailViewController() -} diff --git a/Pinit/Pinit/Views/PinDetail/ReviewCell.swift b/Pinit/Pinit/Views/PinDetail/ReviewCell.swift index 1ec57c7..fcc08ab 100644 --- a/Pinit/Pinit/Views/PinDetail/ReviewCell.swift +++ b/Pinit/Pinit/Views/PinDetail/ReviewCell.swift @@ -95,6 +95,3 @@ class ReviewCell: UITableViewCell { ReviewCell() } -#Preview { - PinDetailViewController() -} diff --git a/Pinit/Pinit/Views/Setting/ProducerCollectionViewCell.swift b/Pinit/Pinit/Views/Setting/ProducerCollectionViewCell.swift index 7e48ab3..cfcc4f7 100644 --- a/Pinit/Pinit/Views/Setting/ProducerCollectionViewCell.swift +++ b/Pinit/Pinit/Views/Setting/ProducerCollectionViewCell.swift @@ -20,7 +20,7 @@ class ProducerCollectionViewCell : UICollectionViewCell { public lazy var thumbnailImageView: UIImageView = { let imageView = UIImageView() - imageView.contentMode = .scaleAspectFill + imageView.contentMode = .scaleToFill imageView.backgroundColor = .lightGray return imageView }() @@ -87,3 +87,7 @@ class ProducerCollectionViewCell : UICollectionViewCell { } } } + +#Preview { + SettingViewController() +} diff --git a/Pinit/Pinit/Views/Setting/SettingViewController.swift b/Pinit/Pinit/Views/Setting/SettingViewController.swift index cb300e7..1a51ea8 100644 --- a/Pinit/Pinit/Views/Setting/SettingViewController.swift +++ b/Pinit/Pinit/Views/Setting/SettingViewController.swift @@ -30,13 +30,16 @@ final class SettingViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - view.backgroundColor = .white + navigationController?.setNavigationBarHidden(true, animated: true) + extendedLayoutIncludesOpaqueBars = true + view.backgroundColor = .secondarySystemBackground view.addSubview(produceCollectionView) view.addSubview(resetButton) produceCollectionView.delegate = self produceCollectionView.dataSource = self + produceCollectionView.backgroundColor = .secondarySystemBackground //버튼 레이아웃 설정 resetButton.setTitle("전체 기록 삭제", for: .normal) @@ -78,7 +81,7 @@ final class SettingViewController: UIViewController { extension SettingViewController : UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - let detailVC = PinDetailViewController() //프로필 누르면 상세 화면으로 + let detailVC = PinDetailViewController(PinEntity.producerData[indexPath.row]) //프로필 누르면 상세 화면으로 present(detailVC, animated: true ,completion: nil ) } @@ -104,8 +107,8 @@ extension SettingViewController : UICollectionViewDelegate, UICollectionViewDele extension SettingViewController { private func autoLayout() { resetButton.snp.makeConstraints { - $0.bottom.equalTo(view.safeAreaLayoutGuide) - $0.height.equalTo(70) + $0.bottom.equalTo(view.safeAreaLayoutGuide).inset(10) + $0.height.equalTo(60) $0.leading.equalToSuperview().inset(10) $0.trailing.equalToSuperview().offset(-10) } @@ -113,7 +116,7 @@ extension SettingViewController { produceCollectionView.snp.makeConstraints { $0.top.equalTo(view.safeAreaLayoutGuide).inset(10) $0.width.equalToSuperview() - $0.bottom.equalTo(resetButton.snp.top) + $0.bottom.equalTo(resetButton.snp.top).offset(-10) } } }