Skip to content

Instantly share code, notes, and snippets.

@StanislavK
Created February 22, 2018 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StanislavK/5265609fb2d33b00854f1ac0b082e8a2 to your computer and use it in GitHub Desktop.
Save StanislavK/5265609fb2d33b00854f1ac0b082e8a2 to your computer and use it in GitHub Desktop.
import UIKit
extension UIView {
func pinEdgesToSafeArea(of view: UIView) {
self.translatesAutoresizingMaskIntoConstraints = false
self.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true
self.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
self.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true
self.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true
}
func pinEdges(to view: UIView) {
self.translatesAutoresizingMaskIntoConstraints = false
self.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
self.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
self.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
self.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment