Created
July 16, 2020 10:21
-
-
Save stevencurtis/cdf96232d905bf7f5462dc59ae03831f to your computer and use it in GitHub Desktop.
loadviewconstraints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func loadView() { | |
self.view = UIView() | |
self.view.backgroundColor = UIColor(displayP3Red: 238/255, green: 240/255, blue: 238/255, alpha: 1.0) | |
let navHeight = self.navigationController?.navigationBar.frame.height | |
guard let backgroundImage = UIImage(named:"city") else {return} | |
city.image = backgroundImage | |
city.clipsToBounds = true | |
self.view.addSubview(city) | |
city.translatesAutoresizingMaskIntoConstraints = false | |
city2.image = backgroundImage | |
city2.clipsToBounds = true | |
self.view.addSubview(city2) | |
city2.translatesAutoresizingMaskIntoConstraints = false | |
let ratio: CGFloat = 3809 / 1257 | |
guard let treeImage = UIImage(named: "tree0") else {return} | |
tree0.image = treeImage | |
tree0.clipsToBounds = true | |
tree0.translatesAutoresizingMaskIntoConstraints = false | |
tree0.contentMode = .scaleAspectFit | |
self.view.addSubview(tree0) | |
manImage.contentMode = .scaleAspectFit | |
manImage.translatesAutoresizingMaskIntoConstraints = false | |
self.view.addSubview(manImage) | |
NSLayoutConstraint.activate([ | |
city.heightAnchor.constraint(equalToConstant: 300), | |
city.widthAnchor.constraint(equalTo: city.heightAnchor, multiplier: ratio), | |
city.centerYAnchor.constraint(equalTo: self.view.centerYAnchor, constant: (navHeight ?? 0)), | |
city.leadingAnchor.constraint(equalTo: self.view.leadingAnchor), | |
city2.heightAnchor.constraint(equalToConstant: 300), | |
city2.widthAnchor.constraint(equalTo: city2.heightAnchor, multiplier: ratio), | |
city2.leadingAnchor.constraint(equalTo: city.trailingAnchor), | |
city2.centerYAnchor.constraint(equalTo: self.view.centerYAnchor, constant: (navHeight ?? 0)), | |
manImage.widthAnchor.constraint(equalToConstant: 97), | |
manImage.heightAnchor.constraint(equalToConstant: 97), | |
manImage.centerXAnchor.constraint(equalTo: self.view.centerXAnchor), | |
manImage.bottomAnchor.constraint(equalTo: self.city.bottomAnchor), | |
tree0.bottomAnchor.constraint(equalTo: self.city.bottomAnchor), | |
tree0.heightAnchor.constraint(equalToConstant: 150), | |
tree0.widthAnchor.constraint(equalTo: tree0.widthAnchor, multiplier: 1.0) | |
]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment