Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kaakati/k-autolayout

An AutoLayout Extension for iOS written in Swift 3 that is very easy to use.
https://github.com/kaakati/k-autolayout

autolayout autolayout-constraints ios purelayout swift swift-3 swift-language swift3

Last synced: about 1 month ago
JSON representation

An AutoLayout Extension for iOS written in Swift 3 that is very easy to use.

Awesome Lists containing this project

README

        

## K-AutoLayout
#### An Autolayout Extension for iOS written in Swift 3

An AutoLayout Extension for iOS written in Swift 3 that is very easy to use.

#### HOW TO USE:
Just copy the `AutoLayout.swift` file to your project.

### Example
Add yourView as Subview
```swift
var yourView : UILabel = {
let label = UILabel()
label.text = "Your UILabel Text"
label.textAlignment = .center
label.translatesAutoresizingMaskIntoConstraints = false // Don't Forget to add this line.
return label
}()

view.addSubview(yourView)
```

#### Assign AutoLayout as follow `anchorToTop` if you don't want to set margins:

```swift
yourView.anchorToTop(top: view.topAnchor, left: view.leftAnchor, bottom: nil, right: view.rightAnchor)
```

##### OR

#### Assign AutoLayout as follow `anchorWithConstantsToTop` if you want to set margins:

```swift
yourView.anchorWithConstantsToTop(top: view.topAnchor, left: view.leftAnchor, bottom: nil, right: view.rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0)
```

If you want your view to connect to superview bottom edge set `bottom: view.bottomAnchor`

##### OR

To add a `secondView` below `yourView` set it's top: as `yourView.bottomAnchor`

```swift
secondView.anchorWithConstantsToTop(top: yourView.bottomAnchor, left: view.leftAnchor, bottom: nil, right: view.rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0)
```