From e963970c62bd9fb8007694143fb90ecaea198da2 Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Fri, 25 Mar 2022 10:02:00 +1100 Subject: ForayNewTableViewCell -> ForayTableViewCell --- foray/Scenes/ForayNewTableViewCell.swift | 84 ----------------------------- foray/Scenes/ForayTableViewCell.swift | 84 +++++++++++++++++++++++++++++ foray/Scenes/ForayTableViewController.swift | 4 +- 3 files changed, 86 insertions(+), 86 deletions(-) delete mode 100644 foray/Scenes/ForayNewTableViewCell.swift create mode 100644 foray/Scenes/ForayTableViewCell.swift (limited to 'foray/Scenes') diff --git a/foray/Scenes/ForayNewTableViewCell.swift b/foray/Scenes/ForayNewTableViewCell.swift deleted file mode 100644 index 224709a..0000000 --- a/foray/Scenes/ForayNewTableViewCell.swift +++ /dev/null @@ -1,84 +0,0 @@ -// -// ForayNewTableViewCell.swift -// foray -// -// Created by Nicholas Tay on 18/3/2022. -// - -import UIKit -import SnapKit - -class ForayNewTableViewCell: UITableViewCell { - - let container: UIView = UIView() - - let nameLabel: UILabel = { - let l = UILabel() - l.font = UIFont.preferredFont(forTextStyle: .headline) - l.numberOfLines = 3 - l.adjustsFontForContentSizeCategory = true - return l - }() - - let descLabel: UILabel = { - let l = UILabel() - l.font = UIFont.preferredFont(forTextStyle: .caption1) - 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) - initialiseViews() - } - - required init?(coder: NSCoder) { - fatalError("unreachable") - } - - private func initialiseViews() { - contentView.addSubview(container) - container.addSubview(nameLabel) - container.addSubview(descLabel) - container.addSubview(itemImageView) - setupConstraints() - } - - private func setupConstraints() { - container.snp.makeConstraints { (make) in - make.edges.equalTo(contentView.snp.margins) - } - - let imageWidth = 64 - let imageHeight = 38 - nameLabel.snp.makeConstraints { (make) in - make.top.equalToSuperview() - make.leading.equalToSuperview() - make.trailing.equalTo(itemImageView.snp.trailing).inset(imageWidth) - } - descLabel.snp.makeConstraints { (make) in - make.top.equalTo(nameLabel.snp.bottom) - make.leading.equalToSuperview() - make.bottom.equalToSuperview() - make.trailing.equalTo(itemImageView.snp.trailing).inset(imageWidth) - } - itemImageView.snp.makeConstraints { (make) in - make.top.equalToSuperview() - make.trailing.equalToSuperview() - make.width.equalTo(imageWidth) - make.height.equalTo(imageHeight) - } - } - - public func setData(name: String, desc: String, img: UIImage) { - nameLabel.text = name - descLabel.text = desc - itemImageView.image = img - } -} diff --git a/foray/Scenes/ForayTableViewCell.swift b/foray/Scenes/ForayTableViewCell.swift new file mode 100644 index 0000000..3849169 --- /dev/null +++ b/foray/Scenes/ForayTableViewCell.swift @@ -0,0 +1,84 @@ +// +// ForayNewTableViewCell.swift +// foray +// +// Created by Nicholas Tay on 18/3/2022. +// + +import UIKit +import SnapKit + +class ForayTableViewCell: UITableViewCell { + + let container: UIView = UIView() + + let nameLabel: UILabel = { + let l = UILabel() + l.font = UIFont.preferredFont(forTextStyle: .headline) + l.numberOfLines = 3 + l.adjustsFontForContentSizeCategory = true + return l + }() + + let descLabel: UILabel = { + let l = UILabel() + l.font = UIFont.preferredFont(forTextStyle: .caption1) + 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) + initialiseViews() + } + + required init?(coder: NSCoder) { + fatalError("unreachable") + } + + private func initialiseViews() { + contentView.addSubview(container) + container.addSubview(nameLabel) + container.addSubview(descLabel) + container.addSubview(itemImageView) + setupConstraints() + } + + private func setupConstraints() { + container.snp.makeConstraints { (make) in + make.edges.equalTo(contentView.snp.margins) + } + + let imageWidth = 64 + let imageHeight = 38 + nameLabel.snp.makeConstraints { (make) in + make.top.equalToSuperview() + make.leading.equalToSuperview() + make.trailing.equalTo(itemImageView.snp.trailing).inset(imageWidth) + } + descLabel.snp.makeConstraints { (make) in + make.top.equalTo(nameLabel.snp.bottom) + make.leading.equalToSuperview() + make.bottom.equalToSuperview() + make.trailing.equalTo(itemImageView.snp.trailing).inset(imageWidth) + } + itemImageView.snp.makeConstraints { (make) in + make.top.equalToSuperview() + make.trailing.equalToSuperview() + make.width.equalTo(imageWidth) + make.height.equalTo(imageHeight) + } + } + + public func setData(name: String, desc: String, img: UIImage) { + nameLabel.text = name + descLabel.text = desc + itemImageView.image = img + } +} diff --git a/foray/Scenes/ForayTableViewController.swift b/foray/Scenes/ForayTableViewController.swift index baa0e6b..72d3569 100644 --- a/foray/Scenes/ForayTableViewController.swift +++ b/foray/Scenes/ForayTableViewController.swift @@ -30,7 +30,7 @@ class ForayTableViewController: UITableViewController, ForayCoordinated { tableView.rowHeight = UITableView.automaticDimension // Register our custom cell - tableView.register(ForayNewTableViewCell.self, forCellReuseIdentifier: "ForayNewTableViewCell") + tableView.register(ForayTableViewCell.self, forCellReuseIdentifier: "ForayTableViewCell") // Not sure if this is the right way to go about this... coordinator?.showLoading() @@ -85,7 +85,7 @@ class ForayTableViewController: UITableViewController, ForayCoordinated { icon = UIImage(named: "spy")! } - let cell: ForayNewTableViewCell = tableView.dequeueReusableCell(withIdentifier: "ForayNewTableViewCell", for: indexPath) as! ForayNewTableViewCell + let cell: ForayTableViewCell = tableView.dequeueReusableCell(withIdentifier: "ForayTableViewCell", for: indexPath) as! ForayTableViewCell cell.setData(name: item.name, desc: type + "ID: " + item.id, img: icon) return cell } -- cgit