From 0ea8e123352f7d60e200c62d07daa207a4327a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A7=80=EB=AF=BC?= Date: Tue, 27 Aug 2024 19:41:43 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=A9=20::=20Student=20-=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 학생 컬렉션 뷰 퍼블리싱 합니다. --- .../10__CMD_iOS/StudentViewController.swift | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 10__CMD_iOS/10__CMD_iOS/StudentViewController.swift diff --git a/10__CMD_iOS/10__CMD_iOS/StudentViewController.swift b/10__CMD_iOS/10__CMD_iOS/StudentViewController.swift new file mode 100644 index 0000000..937ed2c --- /dev/null +++ b/10__CMD_iOS/10__CMD_iOS/StudentViewController.swift @@ -0,0 +1,112 @@ +import UIKit +import SnapKit +import Then + +class StudentViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { + + var collectionView: UICollectionView! + let studentImage = UIImage(named: "student") + + let titleLabel = UILabel().then { + $0.text = "학생정보" + $0.textColor = .black + $0.font = UIFont.systemFont(ofSize: 15, weight: .bold) + $0.textAlignment = .center + } + + let subView = UIView().then { + $0.layer.borderColor = UIColor.subView.cgColor + $0.layer.borderWidth = 4 + $0.layer.cornerRadius = 20 + } + + let subLabel = UILabel().then { + $0.text = "1-1" + $0.textColor = .black + $0.font = UIFont.systemFont(ofSize: 15, weight: .regular) + $0.textAlignment = .center + } + + let line = UIView().then { + $0.backgroundColor = .meal + } + + override func viewDidLoad() { + super.viewDidLoad() + + view.backgroundColor = .white + + let layout = UICollectionViewFlowLayout().then { + $0.minimumInteritemSpacing = 17 + $0.minimumLineSpacing = 30 + $0.sectionInset = UIEdgeInsets(top: 74, left: 24, bottom: 0, right: 24) + $0.itemSize = CGSize(width: 73, height: 71) + } + + collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout).then { + $0.backgroundColor = .white + $0.dataSource = self + $0.delegate = self + $0.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "cell") + } + + view.addSubview(titleLabel) + view.addSubview(subView) + view.addSubview(subLabel) + view.addSubview(line) + view.addSubview(collectionView) + + + + titleLabel.snp.makeConstraints { + $0.top.equalToSuperview().inset(68) + $0.centerX.equalToSuperview() + } + + subView.snp.makeConstraints { + $0.top.equalTo(titleLabel.snp.bottom).offset(22) + $0.left.right.equalToSuperview().inset(17) + $0.height.equalTo(43) + } + + subLabel.snp.makeConstraints { + $0.center.equalTo(subView) + } + + line.snp.makeConstraints { + $0.top.equalTo(subView.snp.bottom).offset(65) + $0.left.right.equalToSuperview().inset(1) + $0.height.equalTo(1) + } + + collectionView.snp.makeConstraints { + $0.top.equalTo(line.snp.bottom).offset(10) + $0.left.right.bottom.equalToSuperview() + } + } + + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return 16 + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) + + let imageView = UIImageView(image: studentImage).then { + $0.contentMode = .scaleAspectFill + $0.clipsToBounds = true + } + + cell.contentView.subviews.forEach { $0.removeFromSuperview() } + cell.contentView.addSubview(imageView) + + imageView.snp.makeConstraints { + $0.edges.equalToSuperview() + $0.width.equalTo(73) + $0.height.equalTo(71) + } + + return cell + } +} +