Skip to content

Instantly share code, notes, and snippets.

@rawnly
Last active May 17, 2019 11:21
Show Gist options
  • Save rawnly/605bc04dea7959fd4b9931dee05ddb5e to your computer and use it in GitHub Desktop.
Save rawnly/605bc04dea7959fd4b9931dee05ddb5e to your computer and use it in GitHub Desktop.
/// 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