aboutsummaryrefslogtreecommitdiff
path: root/foray/ForayNewTableViewCell.swift
diff options
context:
space:
mode:
authorNicholas Tay <nick@windblume.net>2022-03-18 14:48:57 +1100
committerNicholas Tay <nick@windblume.net>2022-03-18 14:49:54 +1100
commita44529a1c62ba58ed09c029f2a0f9c9e36099f21 (patch)
tree5461ed40281b28fe7a58f822083c484a3143a0f1 /foray/ForayNewTableViewCell.swift
parentf45d90ba504496e68d6a4cb2f7f887c011e9b19d (diff)
downloadforayios-a44529a1c62ba58ed09c029f2a0f9c9e36099f21.tar.gz
forayios-a44529a1c62ba58ed09c029f2a0f9c9e36099f21.tar.bz2
forayios-a44529a1c62ba58ed09c029f2a0f9c9e36099f21.zip
Add back in description label and image to custom cell
I don't think this 100% is the correct way with SnapKit. Need to seek advice and improve the constraints. However, an improvement over before is that the accessibility font sizes actually do work as intended now! Now to add back in the segues somehow...
Diffstat (limited to '')
-rw-r--r--foray/ForayNewTableViewCell.swift55
1 files changed, 49 insertions, 6 deletions
diff --git a/foray/ForayNewTableViewCell.swift b/foray/ForayNewTableViewCell.swift
index b2b22af..e679a93 100644
--- a/foray/ForayNewTableViewCell.swift
+++ b/foray/ForayNewTableViewCell.swift
@@ -10,7 +10,27 @@ import SnapKit
class ForayNewTableViewCell: UITableViewCell {
- let nameLabel: UILabel = UILabel()
+ let container: UIView = UIView()
+
+ let nameLabel: UILabel = {
+ let l = UILabel()
+ l.font = UIFont.preferredFont(forTextStyle: .headline)
+ l.adjustsFontForContentSizeCategory = true
+ return l
+ }()
+
+ let descLabel: UILabel = {
+ let l = UILabel()
+ l.font = UIFont.preferredFont(forTextStyle: .body)
+ l.adjustsFontForContentSizeCategory = true
+ return l
+ }()
+
+ let itemImageView: UIImageView = {
+ let iv = UIImageView()
+ iv.contentMode = .scaleAspectFit
+ return iv
+ }()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
@@ -22,18 +42,41 @@ class ForayNewTableViewCell: UITableViewCell {
}
private func initialiseViews() {
- contentView.addSubview(nameLabel)
+ contentView.addSubview(container)
+ container.addSubview(nameLabel)
+ container.addSubview(descLabel)
+ container.addSubview(itemImageView)
setupConstraints()
}
private func setupConstraints() {
+ container.snp.makeConstraints { (make) in
+ make.top.bottom.equalToSuperview()
+ make.trailing.leading.equalToSuperview().inset(12) // better way to do this?
+ }
+
nameLabel.snp.makeConstraints { (make) in
- make.top.bottom.equalToSuperview().inset(8)
- make.leading.trailing.equalToSuperview().inset(8)
+ make.top.equalToSuperview().inset(8)
+ make.leading.equalToSuperview().inset(8)
+ make.trailing.equalTo(itemImageView.snp.trailing).inset(75) // better way to do this?
+ }
+ descLabel.snp.makeConstraints { (make) in
+ make.top.equalTo(nameLabel.snp.bottom).offset(8)
+ make.leading.equalToSuperview().inset(8)
+ make.bottom.equalToSuperview().inset(8)
+ make.trailing.equalTo(itemImageView.snp.trailing).inset(75) // better way to do this?
+ }
+ itemImageView.snp.makeConstraints { (make) in
+ make.top.equalToSuperview().inset(8)
+ make.trailing.equalToSuperview().inset(8)
+ make.width.equalTo(68)
+ make.height.equalTo(44)
}
}
- public func setData(str: String) {
- nameLabel.text = str
+ public func setData(name: String, desc: String, img: UIImage) {
+ nameLabel.text = name
+ descLabel.text = desc
+ itemImageView.image = img
}
}