-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add safeAreaLayoutGuide support for iOS versions below 11.
- Loading branch information
1 parent
28fd717
commit 471f372
Showing
7 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// UIView+iOS10.swift | ||
// Layoutless | ||
// | ||
// Created by Srdan Rasic on 02/05/2018. | ||
// Copyright © 2018 Declarative Hub. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIView { | ||
|
||
private struct AssociatedKeys { | ||
static var safeAreaLayoutGuide = "safeAreaLayoutGuide" | ||
} | ||
|
||
internal var ___safeAreaLayoutGuide: UILayoutGuide { | ||
get { | ||
let layoutGuide = objc_getAssociatedObject(self, &AssociatedKeys.safeAreaLayoutGuide) as? UILayoutGuide | ||
if let layoutGuide = layoutGuide { | ||
return layoutGuide | ||
} else { | ||
let layoutGuide = UILayoutGuide() | ||
addLayoutGuide(layoutGuide) | ||
NSLayoutConstraint.activate([ | ||
layoutGuide.leadingAnchor.constraint(equalTo: leadingAnchor), | ||
layoutGuide.trailingAnchor.constraint(equalTo: trailingAnchor) | ||
]) | ||
objc_setAssociatedObject(self, &AssociatedKeys.safeAreaLayoutGuide, layoutGuide, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) | ||
return layoutGuide | ||
} | ||
} | ||
} | ||
} |
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
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