Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

폴라로이드 이미지 커스텀 뷰 만들기 #85

Merged
merged 4 commits into from
Nov 27, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Foundation

public extension Date {
/// Date 타입을 yyyy.MM.dd 형태의 String으로 변환하여 반환합니다.
func toString() -> String {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy.MM.dd"

return formatter.string(from: self)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import UIKit

final class MHPolaroidPhotoView: UIView {
// MARK: - UI Components
private let photoImageView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit

return imageView
}()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3
원래 개행 넣으셨었나요 ?!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넹 .ᐟ.ᐟ 넣었습니당 .ᐟ.ᐟ

private let captionLabel: UILabel = {
let label = UILabel()
label.numberOfLines = 2
label.font = .ownglyphBerry(size: 12)
label.textColor = .mhTitle

return label
}()

private let creationDateLabel: UILabel = {
let label = UILabel()
label.numberOfLines = 1
label.textAlignment = .right
label.font = .ownglyphBerry(size: 12)
label.textColor = .mhTitle

return label
}()

// MARK: - Initialize
override init(frame: CGRect) {
super.init(frame: frame)

setup()
configureAddSubviews()
configureConstraints()
}

required init?(coder: NSCoder) {
super.init(frame: .zero)

setup()
configureAddSubviews()
configureConstraints()
}

// MARK: - Setup & Configure
private func setup() {
backgroundColor = .white
layer.shadowOffset = CGSize(width: 0, height: 4)
layer.shadowOpacity = 0.4
layer.shadowRadius = 4
layer.masksToBounds = false
}

private func configureAddSubviews() {
addSubview(photoImageView)
addSubview(captionLabel)
addSubview(creationDateLabel)
}

private func configureConstraints() {
photoImageView.setAnchor(top: topAnchor, constantTop: 25,
width: 280, height: 210)
photoImageView.setCenterX(view: self)

captionLabel.setAnchor(top: photoImageView.bottomAnchor, constantTop: 12,
leading: photoImageView.leadingAnchor)

creationDateLabel.setAnchor(bottom: bottomAnchor, constantBottom: 7,
trailing: trailingAnchor, constantTrailing: 12)
}

func configurePhotoImageView(image: UIImage?, caption: String?, creationDate: String) {
photoImageView.image = image
captionLabel.text = caption
creationDateLabel.text = creationDate
}
}
Loading