| 1 | // |
| 2 | // PosterCell.swift |
| 3 | // JomloCollectionView Example |
| 4 | // |
| 5 | // Created by Seto Elkahfi on 2026-01-27. |
| 6 | // Copyright © 2026 Seto Elkahfi. All rights reserved. |
| 7 | // |
| 8 | |
| 9 | import JomloCollectionView |
| 10 | import UIKit |
| 11 | |
| 12 | final class PosterCell: UICollectionViewCell, JomloSelfConfiguringCell { |
| 13 | |
| 14 | private let posterView: UIView = { |
| 15 | let view = UIView() |
| 16 | view.layer.cornerRadius = 8 |
| 17 | view.clipsToBounds = true |
| 18 | return view |
| 19 | }() |
| 20 | |
| 21 | private let titleLabel: UILabel = { |
| 22 | let label = UILabel() |
| 23 | label.font = .preferredFont(forTextStyle: .caption1) |
| 24 | label.adjustsFontForContentSizeCategory = true |
| 25 | label.textColor = .label |
| 26 | label.numberOfLines = 2 |
| 27 | return label |
| 28 | }() |
| 29 | |
| 30 | private let yearLabel: UILabel = { |
| 31 | let label = UILabel() |
| 32 | label.font = .preferredFont(forTextStyle: .caption2) |
| 33 | label.adjustsFontForContentSizeCategory = true |
| 34 | label.textColor = .secondaryLabel |
| 35 | return label |
| 36 | }() |
| 37 | |
| 38 | override init(frame: CGRect) { |
| 39 | super.init(frame: frame) |
| 40 | setupViews() |
| 41 | } |
| 42 | |
| 43 | required init?(coder: NSCoder) { |
| 44 | fatalError("init(coder:) not supported") |
| 45 | } |
| 46 | |
| 47 | func configure(with item: PosterItem) { |
| 48 | titleLabel.text = item.title |
| 49 | yearLabel.text = item.year |
| 50 | posterView.backgroundColor = UIColor(hex: item.colorHex) ?? .gray |
| 51 | } |
| 52 | |
| 53 | private func setupViews() { |
| 54 | let stack = UIStackView(arrangedSubviews: [posterView, titleLabel, yearLabel]) |
| 55 | stack.axis = .vertical |
| 56 | stack.spacing = 4 |
| 57 | stack.translatesAutoresizingMaskIntoConstraints = false |
| 58 | |
| 59 | contentView.addSubview(stack) |
| 60 | NSLayoutConstraint.activate([ |
| 61 | stack.topAnchor.constraint(equalTo: contentView.topAnchor), |
| 62 | stack.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), |
| 63 | stack.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), |
| 64 | stack.bottomAnchor.constraint(lessThanOrEqualTo: contentView.bottomAnchor), |
| 65 | posterView.heightAnchor.constraint(equalTo: posterView.widthAnchor, multiplier: 1.5), |
| 66 | ]) |
| 67 | |
| 68 | isAccessibilityElement = true |
| 69 | accessibilityTraits = .button |
| 70 | } |
| 71 | |
| 72 | override var accessibilityLabel: String? { |
| 73 | get { "\(titleLabel.text ?? ""), \(yearLabel.text ?? "")" } |
| 74 | set {} |
| 75 | } |
| 76 | } |