import UIKit
class ConversionViewController: UIViewController {
// CH3. Challenge
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
print("ConversionViewController loaded its view.")
/*Ch 5. Silver*/
// Create the conversion controller programatically
// Set the view and its background color
view = UIView()
view.backgroundColor = UIColor.systemBackground
// Create labels to add to the view
let fInput = UILabel()
let fLabel = UILabel()
let cOutput = UILabel()
let cLabel = UILabel()
let genLabel = UILabel()
// Initilize the label values
fInput.text = "212"
fInput.textColor = UIColor.black
fInput.font = UIFont.systemFont(ofSize: 70)
fInput.translatesAutoresizingMaskIntoConstraints = false
fLabel.text = "Degrees Fahrenheit"
fLabel.textColor = UIColor.orange
fLabel.font = UIFont.systemFont(ofSize: 36)
fLabel.translatesAutoresizingMaskIntoConstraints = false
genLabel.text = "Is really"
genLabel.textColor = UIColor.black
genLabel.font = UIFont.systemFont(ofSize: 30)
genLabel.translatesAutoresizingMaskIntoConstraints = false
cOutput.text = "100"
cOutput.textColor = UIColor.black
cOutput.font = UIFont.systemFont(ofSize: 70)
cOutput.translatesAutoresizingMaskIntoConstraints = false
cLabel.text = "Degrees Celsius"
cLabel.textColor = UIColor.orange
cLabel.font = UIFont.systemFont(ofSize: 36)
cLabel.translatesAutoresizingMaskIntoConstraints = false
// Add the labels to the view
view.addSubview(fInput)
view.addSubview(fLabel)
view.addSubview(genLabel)
view.addSubview(cOutput)
view.addSubview(cLabel)
// Set the constraints for the labels in the view
let fInputTopConstraint = fInput.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 12)
let fInputCenterConstraint = fInput.centerXAnchor.constraint(equalTo: view.centerXAnchor)
let fLabelTopConstraint = fLabel.topAnchor.constraint(equalTo: fInput.bottomAnchor, constant: 15)
let flabelCenterConstraint = fLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor)
let genLabelTopConstrainat = genLabel.topAnchor.constraint(equalTo: fLabel.bottomAnchor, constant: 15)
let genLabelCenterConstraint = genLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor)
let cOutputTopConstraint = cOutput.topAnchor.constraint(equalTo: genLabel.bottomAnchor, constant: 15)
let cOutputCenterConstraint = cOutput.centerXAnchor.constraint(equalTo: view.centerXAnchor)
let cLabelTopConstraint = cLabel.topAnchor.constraint(equalTo: cOutput.bottomAnchor, constant: 15)
let clabelCenterConstraint = cLabel
.centerXAnchor.constraint(equalTo: view.centerXAnchor)
// Activate the newly created constraints
fInputTopConstraint.isActive = true
fInputCenterConstraint.isActive = true
fLabelTopConstraint.isActive = true
flabelCenterConstraint.isActive = true
genLabelTopConstrainat.isActive = true
genLabelCenterConstraint.isActive = true
cOutputTopConstraint.isActive = true
cOutputCenterConstraint.isActive = true
cLabelTopConstraint.isActive = true
clabelCenterConstraint.isActive = true
/*Ch 5. Silver END*/