Last active
May 17, 2019 11:21
-
-
Save rawnly/605bc04dea7959fd4b9931dee05ddb5e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/// Setup imageView | |
private func setupImageView() { | |
// Set the image | |
imageView.image = UIImage(named: "your-asset-name-here") | |
// Resize the content | |
imageView.contentMode = .scaleAspectFill | |
imageView.layer.masksToBounds = true | |
// That was for testing porpouse only | |
// imageView.backgroundColor = .red | |
// Constraints | |
setupImageViewConstraints() | |
} | |
/// Setup ImageView constraints | |
private func setupImageViewConstraints() { | |
// Disable Autoresizing Masks into Constraints | |
imageView.translatesAutoresizingMaskIntoConstraints = false | |
// Constraints | |
NSLayoutConstraint.activate([ | |
imageView.leadingAnchor.constraint(equalTo: view.leadingAnchor), | |
imageView.trailingAnchor.constraint(equalTo: view.trailingAnchor), | |
imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor), | |
imageView.heightAnchor.constraint(equalToConstant: 250) | |
]) | |
view.layoutIfNeeded() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment