-
Notifications
You must be signed in to change notification settings - Fork 0
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
레시피 리스트UI를 생성해보았습니다. #9
Changes from 1 commit
6764431
10c4c85
69b6ba0
b740a44
68d17da
145bd41
db5e2ef
7a3ba89
db38695
22ee02b
6edb8bb
2a6372c
2be84eb
ee35fb9
34985f7
24d0856
24a71e2
72e9fe8
cf0c78c
15f80f0
833b474
be060c4
99c274e
c0bd5a0
05b2a58
52d89ea
1a760ca
3c03347
7077713
c1bc9a0
4eb8154
e57455d
f0115b8
d3dcc4e
76fdeba
e1a3fc2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// RecipeListViewCell.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 6/12/24. | ||
// | ||
|
||
import UIKit | ||
|
||
class RecipeListViewCell: UICollectionViewCell { | ||
|
||
private let imageView = UIImageView() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네이밍이 좀 더 구체적이면 어떨까요? (예. recipeThumbnailView) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ee35fb9] 변경했습니다 |
||
private let titleLabel = UILabel() | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
setupUI() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
private func setupUI() { | ||
contentView.addSubview(imageView) | ||
contentView.addSubview(titleLabel) | ||
|
||
imageView.translatesAutoresizingMaskIntoConstraints = false | ||
titleLabel.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
NSLayoutConstraint.activate([ | ||
imageView.topAnchor.constraint(equalTo: topAnchor), | ||
imageView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 10), | ||
imageView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -10), | ||
imageView.heightAnchor.constraint(equalTo: heightAnchor, multiplier: 0.75), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 75%면 3:4 사진 비율인건가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 3:4입니다 |
||
|
||
titleLabel.topAnchor.constraint(equalTo: imageView.bottomAnchor, constant: 10), | ||
titleLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 10), | ||
titleLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -10), | ||
titleLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -10), | ||
titleLabel.heightAnchor.constraint(equalTo: heightAnchor, multiplier: 0.15) | ||
]) | ||
|
||
titleLabel.font = .systemFont(ofSize: 16, weight: .bold) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 폰트를 한군데서 정의해서 관리하면 어때요? 나중에 다른데서도 통일성있는 폰트를 사용할 수 있을 것 같아요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
titleLabel.textAlignment = .center | ||
} | ||
|
||
func configure(with viewModel: RecipeListItemViewModel) { | ||
titleLabel.text = viewModel.name | ||
if let imageUrl = viewModel.imageURL { | ||
loadImage(from: imageUrl) | ||
} else { | ||
imageView.image = nil | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이미지가 없으면 이미지뷰에 기본 이미지는 없나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기본이미지를 추가하겠습니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
imageView.contentMode = .scaleAspectFill | ||
imageView.clipsToBounds = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이건 한번만 선언해주면 되는 것 같은데 configure 메서드에 있기보다 setupUI로 이동하면 어떨까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [24a71e2] 변경했습니다 |
||
} | ||
|
||
private func loadImage(from url: URL) { | ||
URLSession.shared.dataTask(with: url) { data, response, error in | ||
guard let data = data, error == nil else { return } | ||
DispatchQueue.main.async { | ||
self.imageView.image = UIImage(data: data) | ||
} | ||
}.resume() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ImageView 에 extension 으로 빠져있으면 다른 화면에서 재사용이 가능한 로직으로 보이는데 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기도 final 챙겨주세요~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[db38695] 변경했습니다