-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardCell.swift
More file actions
55 lines (45 loc) · 1.76 KB
/
CardCell.swift
File metadata and controls
55 lines (45 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import UIKit
class CardCell: UICollectionViewCell {
static let preferredHeight: CGFloat = 272
@IBOutlet private weak var imageView: UIImageView!
@IBOutlet private weak var titleLabel: UILabel!
@IBOutlet private weak var descriptionLabel: UILabel!
@IBOutlet private weak var favoriteButton: UIButton!
private var hero: MarvelHero?
private var onInfoButtonTap: () -> Void = {}
override func awakeFromNib() {
super.awakeFromNib()
imageView.layer.shadowColor = UIColor.black.cgColor
imageView.layer.shadowOffset = .init(width: 0, height: 1)
imageView.layer.shadowOpacity = 0.5
imageView.backgroundColor = UIColor.lightGray
isUserInteractionEnabled = true
bringSubviewToFront(favoriteButton)
}
func configure(for hero: MarvelHero, infoButtonTapped: @escaping () -> Void) {
titleLabel.text = hero.name
descriptionLabel.text = hero.description
imageView.loadImage(at: hero.thumbnail.url(for: .portrait))
self.hero = hero
self.onInfoButtonTap = infoButtonTapped
}
func configure(for product: HeroProduct) {
favoriteButton.isHidden = true
titleLabel.text = product.title
descriptionLabel.text = product.description
guard let thumbnail = product.thumbnail else { return }
imageView.loadImage(at: thumbnail.url(for: .portrait))
}
override func prepareForReuse() {
super.prepareForReuse()
imageView.image = nil
}
@IBAction private func infoButtonTapped() {
onInfoButtonTap()
}
private var isFavoriteHero: Bool {
guard let hero = hero else { return false }
return AppEnvironment.current.favorites.isFavorite(hero.id)
}
}
extension CardCell: NibLoadable {}