Skip to content

Commit

Permalink
feat: DiaryCollectionViewListCell 오토레이아웃 구현
Browse files Browse the repository at this point in the history
ViewController.swift -> DiaryListViewController.swift 네이밍 변경
  • Loading branch information
idinaloq committed Aug 29, 2023
1 parent 5d3d094 commit 93d6c80
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 31 deletions.
8 changes: 4 additions & 4 deletions Diary.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 = "<group>"; };
C739AE26284DF28600741E8F /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
C739AE28284DF28600741E8F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
C739AE28284DF28600741E8F /* DiaryListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryListViewController.swift; sourceTree = "<group>"; };
C739AE2E284DF28600741E8F /* Diary.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Diary.xcdatamodel; sourceTree = "<group>"; };
C739AE30284DF28600741E8F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
C739AE33284DF28600741E8F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -54,7 +54,7 @@
3BBC988D2A9D68290047DE81 /* Controller */ = {
isa = PBXGroup;
children = (
C739AE28284DF28600741E8F /* ViewController.swift */,
C739AE28284DF28600741E8F /* DiaryListViewController.swift */,
);
path = Controller;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
53 changes: 53 additions & 0 deletions Diary/Controller/DiaryListViewController.swift
Original file line number Diff line number Diff line change
@@ -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
}


}
22 changes: 0 additions & 22 deletions Diary/Controller/ViewController.swift

This file was deleted.

62 changes: 57 additions & 5 deletions Diary/View/DiaryCollectionViewListCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)


])
}
}

0 comments on commit 93d6c80

Please sign in to comment.