Untitled
unknown
plain_text
a year ago
4.5 kB
5
Indexable
import UIKit class DeckBuilderViewController: UIViewController { // UI Elements let lengthTextField = UITextField() let widthTextField = UITextField() let heightTextField = UITextField() let buildButton = UIButton() override func viewDidLoad() { super.viewDidLoad() setupUI() } func setupUI() { // Setup text fields lengthTextField.placeholder = "Length" widthTextField.placeholder = "Width" heightTextField.placeholder = "Height" // Setup build button buildButton.setTitle("Build Deck", for: .normal) buildButton.addTarget(self, action: #selector(buildDeck), for: .touchUpInside) // Add subviews view.addSubview(lengthTextField) view.addSubview(widthTextField) view.addSubview(heightTextField) view.addSubview(buildButton) // Layout constraints lengthTextField.translatesAutoresizingMaskIntoConstraints = false widthTextField.translatesAutoresizingMaskIntoConstraints = false heightTextField.translatesAutoresizingMaskIntoConstraints = false buildButton.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ lengthTextField.topAnchor.constraint(equalTo: view.topAnchor, constant: 50), lengthTextField.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), lengthTextField.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20), lengthTextField.heightAnchor.constraint(equalToConstant: 40), widthTextField.topAnchor.constraint(equalTo: lengthTextField.bottomAnchor, constant: 20), widthTextField.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), widthTextField.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20), widthTextField.heightAnchor.constraint(equalToConstant: 40), heightTextField.topAnchor.constraint(equalTo: widthTextField.bottomAnchor, constant: 20), heightTextField.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), heightTextField.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20), heightTextField.heightAnchor.constraint(equalToConstant: 40), buildButton.topAnchor.constraint(equalTo: heightTextField.bottomAnchor, constant: 20), buildButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), buildButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20), buildButton.heightAnchor.constraint(equalToConstant: 40), ]) } @objc func buildDeck() { guard let lengthText = lengthTextField.text, let widthText = widthTextField.text, let heightText = heightTextField.text, let length = Double(lengthText), let width = Double(widthText), let height = Double(heightText) else { // Show error message return } // Calculate deck area let area = length * width // Check compliance with building code let complianceMessage = checkCompliance(area: area, height: height) // Show compliance message let alertController = UIAlertController(title: "Compliance", message: complianceMessage, preferredStyle: .alert) let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } func checkCompliance(area: Double, height: Double) -> String { // Logic to check compliance with building code // This could involve checking against specific regulations and standards // For New Zealand building code, you would need to implement the relevant regulations for deck construction // For simplicity, let's assume a basic compliance check let maxArea: Double = 50.0 let maxHeight: Double = 2.5 if area > maxArea { return "Deck area exceeds maximum allowed." } else if height > maxHeight { return "Deck height exceeds maximum allowed." } else { return "Deck complies with building code." } } }
Editor is loading...