-
Notifications
You must be signed in to change notification settings - Fork 0
/
TitleTableViewCell.swift
87 lines (66 loc) · 2.96 KB
/
TitleTableViewCell.swift
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// TitleTableViewCell.swift
// RepliFlix
//
// Created by Krystal Zhang on 9/14/22.
//
import UIKit
class TitleTableViewCell: UITableViewCell {
static let identifier = "TitleTableViewCell"
private let playTitleButton: UIButton = {
let button = UIButton()
let image = UIImage(systemName: "play.circle", withConfiguration: UIImage.SymbolConfiguration(pointSize: 30))
button.setImage(image, for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
button.tintColor = .white
return button
}()
private let titleLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
private let titlesPosterUIImageView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFill
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.clipsToBounds = true
return imageView
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(titlesPosterUIImageView)
contentView.addSubview(titleLabel)
contentView.addSubview(playTitleButton)
applyConstraints()
}
private func applyConstraints(){
let titlesPosterUIImageViewConstraints = [
titlesPosterUIImageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
titlesPosterUIImageView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 15),
titlesPosterUIImageView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -10),
titlesPosterUIImageView.widthAnchor.constraint(equalToConstant: 100)
]
let titleLabelConstraints = [
titleLabel.leadingAnchor.constraint(equalTo: titlesPosterUIImageView.trailingAnchor, constant: 20),
titleLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
]
let playTitleButtonConstraints = [
playTitleButton.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -20),
playTitleButton.centerYAnchor.constraint(equalTo: contentView.centerYAnchor)
]
NSLayoutConstraint.activate(titlesPosterUIImageViewConstraints)
NSLayoutConstraint.activate(titleLabelConstraints)
NSLayoutConstraint.activate(playTitleButtonConstraints)
}
public func configure(with model: TitleViewModel){
guard let url = URL(string: "https://image.tmdb.org/t/p/w500/\(model.posterURL)") else {
return
}
titlesPosterUIImageView.sd_setImage(with: url, completed: nil)
titleLabel.text = model.titleName
}
required init?(coder: NSCoder){
fatalError()
}
}