Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Pinit/Pinit/Models/ProducerEntity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// ProductEntity.swift
// Pinit
//
// Created by InTak Han on 3/17/25.
//
import UIKit

struct ProducerEntity {
//이름, 위,경도(지역), 생일, 각자사진, 소개, 문구, 기분(날씨)
let title: String
let latitude: Double
let longitude: Double
let date: Date
let mediaPath: UIImage
let description: String?
let weather: String


static let sampleData: [ProducerEntity] = [
//데이터 부분들

ProducerEntity(
title: "JustHm",
latitude: 37.401848,
longitude: 126.922736, //본인 지역의 의,경도
date: Date(), //생년월일
mediaPath: UIImage(named: "JustHMImg")!,
description: "나는 누구 입니다1",
weather: "구름"),

ProducerEntity(
title: "Ikhwan0204",
latitude: 37.502058,
longitude: 126.672010, //본인 지역의 의,경도
date: Date(), //생년월일
mediaPath: UIImage(named: "Ikhwan0204Img")!,
description: "나는 누구 입니다2",
weather: "흐림"),

ProducerEntity(
title: "IntakHan304",
latitude: 37.557385,
longitude: 126.956276, //본인 지역의 의,경도
date: Date(), //생년월일
mediaPath: UIImage(named: "IntakHan304Img")!,
description: "나는 누구 입니다3",
weather: "비"),

ProducerEntity(
title: "HISEHOONAN",
latitude: 38.078549,
longitude: 128.616008, //본인 지역의 의,경도
date: Date(), //생년월일
mediaPath: UIImage(named: "HISEHOONImg")! ,
description: "나는 누구 입니다4",
weather: "눈"),

ProducerEntity(
title: "kut7728",
latitude: 37.484679,
longitude: 126.897968, //본인 지역의 의,경도
date: Date(), //생년월일
mediaPath: UIImage(named: "kut7728Img")! ,
description: "나는 누구 입니다5",
weather: "맑음")
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "HISEHOONImg.jpeg",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Ikhwan0204Img.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "IntakHan304Img.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "JustHMImg.jpeg",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "kut7728Img.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions Pinit/Pinit/Views/Setting/ProducerCollectionViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// MyCollectionViewCell2.swift
// SetUpViewEx
//
// Created by InTak Han on 3/17/25.
//
import UIKit

class ProducerCollectionViewCell : UICollectionViewCell {
//그림자 뷰 추가
public let shadowContainerView: UIView = {
let view = UIView()
view.backgroundColor = .clear
view.layer.shadowColor = UIColor.black.withAlphaComponent(0.25).cgColor
view.layer.shadowOpacity = 1
view.layer.shadowRadius = 4
view.layer.shadowOffset = CGSize(width: 0, height: 4)
return view
}()

public lazy var thumbnailImageView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFill
imageView.backgroundColor = .lightGray
return imageView
}()

public lazy var titleLabel: UILabel = {
let label = UILabel()
label.font = DesignSystemFont.Pretendard_Bold16.value
label.textColor = .black
label.sizeToFit()
return label
}()

public lazy var dateLabel: UILabel = {
let label = UILabel()
label.font = DesignSystemFont.Pretendard_Medium12.value
label.textColor = UIColor(hex: "808080")
label.sizeToFit()
return label
}()

func configure(model: ProducerEntity) {
dateLabel.text = model.date.snakeCaseDateString()
titleLabel.text = model.title
//thumbnailImageView.image = UIImage(systemName: "house")
//프로필에 지정한 이미지가 없다면 기본이미지로 집모양으로 들어간다
thumbnailImageView.image = model.mediaPath
//model.mediaPath ?? UIImage(systemName: "house")
cellSetting()
} //모델(SettingView의 data)에서 데이터 가져오는 부분

override init(frame: CGRect) {
super.init(frame: frame)
self.cellSetting()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func cellSetting() {

contentView.backgroundColor = .white
contentView.layer.cornerRadius = 6
contentView.clipsToBounds = true //contentView에는 cornerRadius

shadowContainerView.addSubview(contentView) //그림자 뷰에 contentView 추가
addSubview(shadowContainerView)

shadowContainerView.snp.makeConstraints { $0.edges.equalToSuperview() }
contentView.snp.makeConstraints { $0.edges.equalToSuperview() }

contentView.addSubviews(thumbnailImageView, titleLabel, dateLabel)

//img.contentMode = .scaleToFill
thumbnailImageView.snp.remakeConstraints {
$0.top.leading.trailing.equalToSuperview().inset(8)
$0.height.equalTo(contentView.frame.width * 0.76)
}
titleLabel.snp.makeConstraints {
$0.top.equalTo(thumbnailImageView.snp.bottom).offset(16)
$0.leading.trailing.equalToSuperview().inset(8)
}
dateLabel.snp.makeConstraints {
$0.top.equalTo(titleLabel.snp.bottom).offset(8)
$0.leading.trailing.equalToSuperview().inset(8)
}
}
}
102 changes: 102 additions & 0 deletions Pinit/Pinit/Views/Setting/SettingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,110 @@
import UIKit

final class SettingViewController: UIViewController {
var data: [ProducerEntity] = ProducerEntity.sampleData
//모델에서 데이터를 가져옴

private let resetButton = UIButton()
private var produceCollectionView : UICollectionView = {

var layout = UICollectionViewFlowLayout()
layout.scrollDirection = .vertical
layout.sectionInset = .zero
let spacing = 5.0
var width: CGFloat = UIScreen.main.bounds.width
width = (width / 2) - (spacing * 1.5)
layout.itemSize = .init(width: width, height: width * 1.23)
layout.minimumInteritemSpacing = spacing
layout.sectionInset = .init(top: 0, left: spacing, bottom: spacing, right: spacing)

let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
return cv
}()

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white

view.addSubview(produceCollectionView)
view.addSubview(resetButton)

produceCollectionView.delegate = self
produceCollectionView.dataSource = self

//버튼 레이아웃 설정
resetButton.setTitle("전체 기록 삭제", for: .normal)
resetButton.addTarget(self, action: #selector(resetAlert), for: .touchUpInside)
resetButton.backgroundColor = .lightGray

autoLayout()
produceCollectionView.register(ProducerCollectionViewCell.self, forCellWithReuseIdentifier: "cell")
}

@objc func resetAlert() {
//버튼이 눌리면 실행되는 부분(Alert)
let alert = UIAlertController(title: "전체 기록 삭제", message: "모든 핀이 삭제됩니다.\n 진행하시겠습니까?", preferredStyle: .alert)

let addAction = UIAlertAction(title: "확인", style: .destructive) { _ in
if let text = alert.textFields?.first?.text, !text.isEmpty {
//1.저장된 내용이 지워지는 내용

//2.삭제되었습니다

}
}

alert.addAction(addAction)
alert.addAction(UIAlertAction(title: "취소", style: .cancel))
present(alert, animated: true)
}
}

extension SettingViewController : UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let detailVC = PinDetailViewController()
present(detailVC, animated: true ,completion: nil )
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { //컬랙션 뷰의 셀 갯수
return data.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? ProducerCollectionViewCell else {
return UICollectionViewCell()
}
cell.configure(model: data[indexPath.row])


return cell
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
//컬렉션 뷰의 셀의 크기
let itemSpacing : CGFloat = 10

let myWidth : CGFloat = (collectionView.bounds.width - itemSpacing * 2) / 2

return CGSize(width: myWidth, height: myWidth * 1.2)
}
}

//오토레이아웃 제약 설정(snapkit) 부분
extension SettingViewController {
private func autoLayout() {
resetButton.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.bottom.equalToSuperview().offset(-90)
$0.height.equalTo(50)
$0.leading.equalTo(10)
}
//컬렉션 뷰 제약 설정 부분 예정
produceCollectionView.snp.makeConstraints {
$0.edges.equalTo(view.safeAreaLayoutGuide)
$0.bottom.equalTo(resetButton.snp.top).offset(-30)
}
}
}

Expand Down