Update docs to reflect current api. (#720)

This commit is contained in:
Glenn 2021-06-08 15:41:14 +09:00 committed by GitHub
parent e5bc2ced4b
commit bfbdca7441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 43 deletions

60
docs.md
View File

@ -96,7 +96,7 @@ let box = UIView()
superview.addSubview(box) superview.addSubview(box)
box.snp.makeConstraints { (make) -> Void in box.snp.makeConstraints { (make) -> Void in
make.edges.equalTo(superview).inset(UIEdgeInsetsMake(20, 20, 20, 20)) make.edges.equalTo(superview).inset(UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20))
} }
``` ```
@ -104,15 +104,15 @@ Not only does this greatly shorten and increase the readability of constraints S
- Determining the best common superview to install the constraints on. - Determining the best common superview to install the constraints on.
- Keeping track of the constrainted installed so they can easily be removed later. - Keeping track of the constrainted installed so they can easily be removed later.
- Ensuring `setTranslatesAutoresizingMaskIntoConstraints(false)` is called on all appropriate views. - Ensuring `translatesAutoresizingMaskIntoConstraints = false` is called on all appropriate views.
### Not all things are created equal ### Not all things are created equal
> `.equalTo` equivalent to **NSLayoutRelation.Equal** > `.equalTo` equivalent to **NSLayoutConstraint.Relation.equal**
> `.lessThanOrEqualTo` equivalent to **NSLayoutRelation.LessThanOrEqual** > `.lessThanOrEqualTo` equivalent to **NSLayoutConstraint.Relation.lessThanOrEqual**
> `.greaterThanOrEqualTo` equivalent to **NSLayoutRelation.GreaterThanOrEqual** > `.greaterThanOrEqualTo` equivalent to **NSLayoutConstraint.Relation.greaterThanOrEqual**
These three equality constraints accept one argument which can be any of the following: These three equality constraints accept one argument which can be any of the following:
@ -124,17 +124,17 @@ make.centerX.lessThanOrEqualTo(view2.snp.left)
ViewAttribute | NSLayoutAttribute ViewAttribute | NSLayoutAttribute
------------------------- | -------------------------- ------------------------- | --------------------------
view.snp.left | NSLayoutAttribute.left view.snp.left | NSLayoutConstraint.Attribute.left
view.snp.right | NSLayoutAttribute.right view.snp.right | NSLayoutConstraint.Attribute.right
view.snp.top | NSLayoutAttribute.top view.snp.top | NSLayoutConstraint.Attribute.top
view.snp.bottom | NSLayoutAttribute.bottom view.snp.bottom | NSLayoutConstraint.Attribute.bottom
view.snp.leading | NSLayoutAttribute.leading view.snp.leading | NSLayoutConstraint.Attribute.leading
view.snp.trailing | NSLayoutAttribute.trailing view.snp.trailing | NSLayoutConstraint.Attribute.trailing
view.snp.width | NSLayoutAttribute.width view.snp.width | NSLayoutConstraint.Attribute.width
view.snp.height | NSLayoutAttribute.height view.snp.height | NSLayoutConstraint.Attribute.height
view.snp.centerX | NSLayoutAttribute.centerX view.snp.centerX | NSLayoutConstraint.Attribute.centerX
view.snp.centerY | NSLayoutAttribute.centerY view.snp.centerY | NSLayoutConstraint.Attribute.centerY
view.snp.lastBaseline | NSLayoutAttribute.lastBaseline view.snp.lastBaseline | NSLayoutConstraint.Attribute.lastBaseline
#### 2. UIView/NSView #### 2. UIView/NSView
@ -304,36 +304,10 @@ func changeButtonPosition() {
} }
``` ```
### Snap view to topLayoutGuide and bottomLayoutGuide
`topLayoutGuide.snp.bottom` is similar to `topLayoutGuide.bottomAnchor` and you can also use `bottomLayoutGuide.snp.top` to align view on top of UITabBar.
```swift
import SnapKit
class MyViewController: UIVewController {
lazy var tableView = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(tableView)
tableView.snp.makeConstraints { (make) -> Void in
make.top.equalTo(self.topLayoutGuide.snp.bottom)
make.left.equalTo(view)
make.right.equalTo(view)
make.bottom.equalTo(self.bottomLayoutGuide.snp.top)
}
}
}
```
### Snap view to safeAreaLayoutGuide ### Snap view to safeAreaLayoutGuide
Just like `topLayoutGuide` and `bottomLayoutGuide` using iPhone X's new `safeAreaLayoutGuide` is easy: `topLayoutGuide` and `bottomLayoutGuide` were deprecated in `iOS 11`. Use `safeAreaLayoutGuide`:
```swift ```swift
import SnapKit import SnapKit