blob: f87e4b05c997c3bff7daab854b56cf60f32232b9 (
plain) (
tree)
|
|
//
// ForayDetailViewController.swift
// foray
//
// Created by Nicholas Tay on 16/3/2022.
//
import UIKit
class ForayDetailViewController: UIViewController, ForayCoordinated {
var coordinator: ForayCoordinator?
let scrollView: UIScrollView = {
let sv = UIScrollView()
sv.alwaysBounceVertical = true // just for fun
return sv
}()
let container = UIView()
let nameLabel: UILabel = {
let l = UILabel()
l.font = UIFont.preferredFont(forTextStyle: .largeTitle)
l.adjustsFontForContentSizeCategory = true
l.numberOfLines = 3
l.textAlignment = .center
return l
}()
let itemImageView: UIImageView = {
let iv = UIImageView()
iv.contentMode = .scaleAspectFit
return iv
}()
let descLabel: UILabel = {
let l = UILabel()
l.font = UIFont.preferredFont(forTextStyle: .body)
l.adjustsFontForContentSizeCategory = true
l.numberOfLines = 10
return l
}()
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Details"
self.view.backgroundColor = .systemBackground
initialiseViews()
}
private func initialiseViews() {
self.view.addSubview(scrollView)
scrollView.addSubview(container)
container.addSubview(nameLabel)
container.addSubview(itemImageView)
container.addSubview(descLabel)
setupConstraints()
}
private func setupConstraints() {
scrollView.snp.makeConstraints { (make) in
make.edges.equalTo(self.view.snp.margins)
}
container.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
make.width.equalTo(scrollView.snp.width)
}
nameLabel.snp.makeConstraints { (make) in
make.top.equalToSuperview().inset(16)
make.leading.trailing.equalToSuperview().inset(8)
}
itemImageView.snp.makeConstraints { (make) in
make.top.equalTo(nameLabel.snp.bottom).offset(32)
make.leading.trailing.equalToSuperview()
make.height.equalTo(150)
}
descLabel.snp.makeConstraints { (make) in
make.top.equalTo(itemImageView.snp.bottom).offset(32)
make.leading.trailing.equalToSuperview()
make.bottom.equalTo(container.snp.bottom).inset(16)
}
}
public func setDetails(name: String, description: String, image: UIImage) {
nameLabel.text = name
descLabel.text = description
itemImageView.image = image
}
}
|