aboutsummaryrefslogtreecommitdiff
path: root/foray
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--foray/ForayNewTableViewCell.swift55
-rw-r--r--foray/ForayTableViewController.swift26
2 files changed, 62 insertions, 19 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
}
}
diff --git a/foray/ForayTableViewController.swift b/foray/ForayTableViewController.swift
index 8f11285..6a0baa1 100644
--- a/foray/ForayTableViewController.swift
+++ b/foray/ForayTableViewController.swift
@@ -55,6 +55,8 @@ class ForayTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
+ tableView.rowHeight = UITableView.automaticDimension
+
// Register our custom cell
tableView.register(ForayNewTableViewCell.self, forCellReuseIdentifier: "ForayNewTableViewCell")
@@ -153,21 +155,19 @@ class ForayTableViewController: UITableViewController {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let item = self.sections[indexPath.section].items[indexPath.row]
-// let cell: ForayTableViewCell
-// switch item.type {
-// case .item:
-// cell = tableView.dequeueReusableCell(withIdentifier: "ForayCell", for: indexPath) as! ForayTableViewCell
-// cell.cellItemImage?.image = UIImage(named: item.id)
-// case .quest:
-// cell = tableView.dequeueReusableCell(withIdentifier: "ForayQuestCell", for: indexPath) as! ForayTableViewCell
-// }
-//
-// cell.cellItemName?.text = item.name
-// cell.cellItemSubtitle?.text = "ID: " + item.id
+ let type: String
+ let icon: UIImage
+ switch item.type {
+ case .item:
+ type = "Item"
+ icon = UIImage(named: item.id)!
+ case .quest:
+ type = "Quest"
+ icon = UIImage(named: "spy")!
+ }
let cell: ForayNewTableViewCell = tableView.dequeueReusableCell(withIdentifier: "ForayNewTableViewCell", for: indexPath) as! ForayNewTableViewCell
- cell.setData(str: item.name)
-
+ cell.setData(name: item.name, desc: type + "ID: " + item.id, img: icon)
return cell
}