Select Git revision
ViewController.swift
ViewController.swift 2.46 KiB
//
// ViewController.swift
// Pendu
//
// Created by Sofiane Lasri-Trienpont on 09/05/2023.
//
import UIKit
extension UIView {
func addBackground(imageName: String = "fond_acceuil.png", contentMode: UIView.ContentMode = .scaleToFill) {
// setup the UIImageView
let backgroundImageView = UIImageView(frame: UIScreen.main.bounds)
backgroundImageView.image = UIImage(named: imageName)
backgroundImageView.contentMode = contentMode
backgroundImageView.translatesAutoresizingMaskIntoConstraints = false
addSubview(backgroundImageView)
sendSubviewToBack(backgroundImageView)
// adding NSLayoutConstraints
let leadingConstraint = NSLayoutConstraint(item: backgroundImageView, attribute: .leading, relatedBy: .equal, toItem: self, attribute: .leading, multiplier: 1.0, constant: 0.0)
let trailingConstraint = NSLayoutConstraint(item: backgroundImageView, attribute: .trailing, relatedBy: .equal, toItem: self, attribute: .trailing, multiplier: 1.0, constant: 0.0)
let topConstraint = NSLayoutConstraint(item: backgroundImageView, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: 0.0)
let bottomConstraint = NSLayoutConstraint(item: backgroundImageView, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .bottom, multiplier: 1.0, constant: 0.0)
NSLayoutConstraint.activate([leadingConstraint, trailingConstraint, topConstraint, bottomConstraint])
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
view.addBackground()
super.viewDidLoad()
let image = UIImage(named: "humain")
let imageView = UIImageView(image: image!)
imageView.frame = CGRect(x: 50, y: 300, width: 250, height: 250)
view.addSubview(imageView)
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
label.center = CGPoint(x: 160, y: 230)
label.font = UIFont(name: "whatever it takes", size: 40)
label.textAlignment = .center
label.textColor = UIColor.white
label.text = "Pendu"
self.view.addSubview(label)
// let ButtonLetter = ButtonTemplate(frame: CGRect(x: 1000, y: 1500, width: 150, height: 30))
// view.addSubview(ButtonLetter)
// ButtonLetter.center = view.center
// ButtonLetter.configure(with: ButtonTemplateViewModel(primaryColor: "Commencer"))
}
}