Skip to content

Instantly share code, notes, and snippets.

@Pircate
Created February 21, 2019 10:03
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 Pircate/52a3aeb2c59695f6e997a6f3bd19242b to your computer and use it in GitHub Desktop.
Save Pircate/52a3aeb2c59695f6e997a6f3bd19242b to your computer and use it in GitHub Desktop.
import SnapKit
public struct ConstraintViewControllerDSL {
fileprivate let base: UIViewController
init(_ base: UIViewController) {
self.base = base
}
}
extension UIViewController {
public var snp: ConstraintViewControllerDSL {
return ConstraintViewControllerDSL(self)
}
}
public extension ConstraintViewControllerDSL {
var topLayoutGuide: ConstraintItem {
if #available(iOS 11.0, *) {
return base.view.safeAreaLayoutGuide.snp.top
} else {
return base.topLayoutGuide.snp.bottom
}
}
var bottomLayoutGuide: ConstraintItem {
if #available(iOS 11.0, *) {
return base.view.safeAreaLayoutGuide.snp.bottom
} else {
return base.bottomLayoutGuide.snp.top
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment