https://github.com/truffls/compatible-layout-anchors-ios
Automatically apply top/bottom layout anchors without having to check safe area compatibility
https://github.com/truffls/compatible-layout-anchors-ios
Last synced: about 2 months ago
JSON representation
Automatically apply top/bottom layout anchors without having to check safe area compatibility
- Host: GitHub
- URL: https://github.com/truffls/compatible-layout-anchors-ios
- Owner: truffls
- License: mit
- Created: 2017-12-05T14:08:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-24T13:29:21.000Z (about 7 years ago)
- Last Synced: 2025-02-24T16:07:41.577Z (3 months ago)
- Language: Swift
- Homepage:
- Size: 2.13 MB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README



An easy way to support iOS 11 safe area anchors and iOS <=10 top/bottom layout guides at the same time. CompatibleLayoutAnchors takes away the boiler plate code to check which layout anchors to use.
### Problem
If you're using iOS 11's safe area and NIBs for your interfaces the fallback constraints for iOS <=10 falls back to the superview's anchors instead of top/bottom layout guides.
In a usual workflow you would setup your nib and looking OK in Interface Builder.

But in iOS <=10 it looks broken.
| Actual | Expected |
| ------ | -------- |
|  |  |### Install via Cocoapods
Add following to your `Podfile`:
```ruby
use_frameworks!
pod 'CompatibleLayoutAnchors'
```### How to use
You have your layout in a NIB file ready with all layout constraints. Reference in your view controller the top constraints connected to the safe area top anchor and the bottom constraints connected to the safe area bottom anchor. Use `assignCompatibleConstraint(_:for:)` to reassign the top and bottom constraints with the appropriate constraints.
```swift
assignCompatibleConstraint(&myTopConstraint, for: .top)
```### Example
This code fits to the screenshots above.
```swift
class ViewController: UIViewController {@IBOutlet weak var headlineLabelTopConstraint: NSLayoutConstraint!
@IBOutlet weak var footnoteLabelBottomConstraint: NSLayoutConstraint!override func viewDidLoad() {
super.viewDidLoad()assignCompatibleConstraint(&headlineLabelTopConstraint, for: .top)
assignCompatibleConstraint(&footnoteLabelBottomConstraint, for: .bottom)
}
}
```### Contribution
Issues and pull requests are welcome!