diff --git a/Diary.xcodeproj/project.pbxproj b/Diary.xcodeproj/project.pbxproj index c81179880..71ed362b8 100644 --- a/Diary.xcodeproj/project.pbxproj +++ b/Diary.xcodeproj/project.pbxproj @@ -10,7 +10,7 @@ 3BBC98902A9D73D70047DE81 /* DiaryCollectionViewListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BBC988F2A9D73D70047DE81 /* DiaryCollectionViewListCell.swift */; }; C739AE25284DF28600741E8F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C739AE24284DF28600741E8F /* AppDelegate.swift */; }; C739AE27284DF28600741E8F /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C739AE26284DF28600741E8F /* SceneDelegate.swift */; }; - C739AE29284DF28600741E8F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C739AE28284DF28600741E8F /* ViewController.swift */; }; + C739AE29284DF28600741E8F /* DiaryListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C739AE28284DF28600741E8F /* DiaryListViewController.swift */; }; C739AE2F284DF28600741E8F /* Diary.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = C739AE2D284DF28600741E8F /* Diary.xcdatamodeld */; }; C739AE31284DF28600741E8F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C739AE30284DF28600741E8F /* Assets.xcassets */; }; C739AE34284DF28600741E8F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C739AE32284DF28600741E8F /* LaunchScreen.storyboard */; }; @@ -22,7 +22,7 @@ C739AE21284DF28600741E8F /* Diary.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Diary.app; sourceTree = BUILT_PRODUCTS_DIR; }; C739AE24284DF28600741E8F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; C739AE26284DF28600741E8F /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; - C739AE28284DF28600741E8F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + C739AE28284DF28600741E8F /* DiaryListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryListViewController.swift; sourceTree = ""; }; C739AE2E284DF28600741E8F /* Diary.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Diary.xcdatamodel; sourceTree = ""; }; C739AE30284DF28600741E8F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; C739AE33284DF28600741E8F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; @@ -54,7 +54,7 @@ 3BBC988D2A9D68290047DE81 /* Controller */ = { isa = PBXGroup; children = ( - C739AE28284DF28600741E8F /* ViewController.swift */, + C739AE28284DF28600741E8F /* DiaryListViewController.swift */, ); path = Controller; sourceTree = ""; @@ -191,7 +191,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - C739AE29284DF28600741E8F /* ViewController.swift in Sources */, + C739AE29284DF28600741E8F /* DiaryListViewController.swift in Sources */, C739AE25284DF28600741E8F /* AppDelegate.swift in Sources */, C739AE27284DF28600741E8F /* SceneDelegate.swift in Sources */, C739AE2F284DF28600741E8F /* Diary.xcdatamodeld in Sources */, diff --git a/Diary/Controller/DiaryListViewController.swift b/Diary/Controller/DiaryListViewController.swift new file mode 100644 index 000000000..ff08975ea --- /dev/null +++ b/Diary/Controller/DiaryListViewController.swift @@ -0,0 +1,53 @@ +// +// Diary - DiaryListViewController.swift +// Created by yagom. +// Copyright © yagom. All rights reserved. +// + +import UIKit + +final class DiaryListViewController: UIViewController { + private let collectionView: UICollectionView = { + let configuration: UICollectionLayoutListConfiguration = UICollectionLayoutListConfiguration(appearance: .plain) + let layout = UICollectionViewCompositionalLayout.list(using: configuration) + let view = UICollectionView(frame: .zero, collectionViewLayout: layout) + view.translatesAutoresizingMaskIntoConstraints = false + view.register(DiaryCollectionViewListCell.self, forCellWithReuseIdentifier: DiaryCollectionViewListCell.identifier) + return view + }() + + override func viewDidLoad() { + super.viewDidLoad() + collectionView.dataSource = self + collectionView.delegate = self + configureUI() + configureAutoLayout() + } + private func configureUI() { + view.addSubview(collectionView) + view.backgroundColor = .systemBackground + } + private func configureAutoLayout() { + let safeArea = view.safeAreaLayoutGuide + NSLayoutConstraint.activate([ + collectionView.topAnchor.constraint(equalTo: safeArea.topAnchor), + collectionView.leadingAnchor.constraint(equalTo: safeArea.leadingAnchor), + collectionView.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor), + collectionView.bottomAnchor.constraint(equalTo: safeArea.bottomAnchor) + ]) + } +} + +extension DiaryListViewController: UICollectionViewDataSource, UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return 1 + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: DiaryCollectionViewListCell.identifier, for: indexPath) + + return cell + } + + +} diff --git a/Diary/Controller/ViewController.swift b/Diary/Controller/ViewController.swift deleted file mode 100644 index d34140851..000000000 --- a/Diary/Controller/ViewController.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// Diary - ViewController.swift -// Created by yagom. -// Copyright © yagom. All rights reserved. -// - -import UIKit - -final class DiaryListViewController: UIViewController { - private let collectionView: UICollectionView = { - let configuration = UICollectionLayoutListConfiguration(appearance: .plain) - let layout = UICollectionViewCompositionalLayout.list(using: configuration) - let view = UICollectionView(frame: .zero, collectionViewLayout: layout) - view.translatesAutoresizingMaskIntoConstraints = false -// view.register(<#T##cellClass: AnyClass?##AnyClass?#>, forCellWithReuseIdentifier: <#T##String#>) - return view - }() - - override func viewDidLoad() { - super.viewDidLoad() - } -} diff --git a/Diary/View/DiaryCollectionViewListCell.swift b/Diary/View/DiaryCollectionViewListCell.swift index 8269f4916..ccc7a647c 100644 --- a/Diary/View/DiaryCollectionViewListCell.swift +++ b/Diary/View/DiaryCollectionViewListCell.swift @@ -8,25 +8,77 @@ import UIKit class DiaryCollectionViewListCell: UICollectionViewListCell { + static let identifier: String = "DiaryCollectionViewListCell" private let titleLabel: UILabel = { - let label = UILabel() - label.text = "타이블레이블" + let label: UILabel = UILabel() + label.text = "타이틀레이블" label.translatesAutoresizingMaskIntoConstraints = false label.numberOfLines = 1 + label.font = .preferredFont(forTextStyle: .title2) return label }() private let dateLabel: UILabel = { - let label = UILabel() - label.text = "데이트레이블" + let label: UILabel = UILabel() + label.text = "2020년 12월 23일" label.translatesAutoresizingMaskIntoConstraints = false label.numberOfLines = 1 + label.font = .preferredFont(forTextStyle: .body) return label }() private let previewLabel: UILabel = { - let label = UILabel() + let label: UILabel = UILabel() label.text = "프리뷰레이블" label.translatesAutoresizingMaskIntoConstraints = false label.numberOfLines = 1 + label.textAlignment = .left + label.setContentHuggingPriority(.init(200), for: .horizontal) + label.font = .preferredFont(forTextStyle: .body) return label }() + private let titleLabelStackView: UIStackView = { + let stackView: UIStackView = UIStackView() + stackView.axis = .vertical + stackView.translatesAutoresizingMaskIntoConstraints = false + return stackView + }() + private let dateAndPreviewStackView: UIStackView = { + let stackView: UIStackView = UIStackView() + stackView.axis = .horizontal + stackView.spacing = 8 + stackView.translatesAutoresizingMaskIntoConstraints = false + return stackView + }() + override init(frame: CGRect) { + super.init(frame: frame) + configureUI() + configureAutoLayout() + } + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + private func configureUI() { + titleLabelStackView.addArrangedSubview(titleLabel) +// titleLabelStackView.addArrangedSubview(dateAndPreviewStackView) + dateAndPreviewStackView.addArrangedSubview(dateLabel) + dateAndPreviewStackView.addArrangedSubview(previewLabel) + contentView.addSubview(titleLabelStackView) + contentView.addSubview(dateAndPreviewStackView) + + self.accessories = [.disclosureIndicator()] + } + private func configureAutoLayout() { + NSLayoutConstraint.activate([ + titleLabelStackView.topAnchor.constraint(equalTo: contentView.topAnchor), + titleLabelStackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), + titleLabelStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), + titleLabelStackView.bottomAnchor.constraint(equalTo: dateAndPreviewStackView.topAnchor, constant: -8), + + + dateAndPreviewStackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), + dateAndPreviewStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), + dateAndPreviewStackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor) + + + ]) + } }