Created
February 22, 2018 15:30
-
-
Save StanislavK/5265609fb2d33b00854f1ac0b082e8a2 to your computer and use it in GitHub Desktop.
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
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