Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pchelnikov/markerkit
A lightweight and easy to use wrapper for Auto Layout Constraints
https://github.com/pchelnikov/markerkit
autolayout carthage cocoapods constraints layout markerkit swift swift-4 ui xcode
Last synced: 3 months ago
JSON representation
A lightweight and easy to use wrapper for Auto Layout Constraints
- Host: GitHub
- URL: https://github.com/pchelnikov/markerkit
- Owner: pchelnikov
- License: mit
- Created: 2017-12-28T10:36:55.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-19T10:11:10.000Z (over 5 years ago)
- Last Synced: 2024-03-15T11:04:20.915Z (10 months ago)
- Topics: autolayout, carthage, cocoapods, constraints, layout, markerkit, swift, swift-4, ui, xcode
- Language: Swift
- Homepage:
- Size: 323 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![MarkerKit](https://github.com/pchelnikov/MarkerKit/blob/master/Assets/marker-kit.jpg)
# MarkerKit
A lightweight and easy to use wrapper for Auto Layout Constraints (iOS 8+ support), inspired by [https://github.com/ustwo/autolayout-helper-swift](https://github.com/ustwo/autolayout-helper-swift)[![License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/pchelnikov/MarkerKit/blob/master/LICENSE)
[![Platform](https://img.shields.io/cocoapods/p/MarkerKit.svg?style=flat)](https://github.com/pchelnikov/MarkerKit)
[![Cocoapods Compatible](https://img.shields.io/cocoapods/v/MarkerKit.svg)](https://cocoapods.org/pods/MarkerKit)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)## Requirements
- iOS 8.0+
- Xcode 9.0+
- Swift 4.0+## Installation
### CocoaPods
You can use [CocoaPods](http://cocoapods.org/?q=MarkerKit).
```bash
platform :ios, '8.0'
use_frameworks!target 'MyApp' do
pod 'MarkerKit'
end
```#### Carthage
You can use [Carthage](https://github.com/Carthage/Carthage).
Specify in Cartfile:```bash
github "pchelnikov/MarkerKit"
```Run `carthage` to build the framework and drag the built MarkerKit.framework into your Xcode project. Follow [build instructions](https://github.com/Carthage/Carthage#getting-started).
### Manually
- Add the `MarkerKit.swift` file to your Xcode project.
## Usage
### Quick Start
```swift
import MarkerKitclass MyViewController: UIViewController {
lazy var myView = UIView()
override func viewDidLoad() {
super.viewDidLoad()view.addSubview(myView)
myView.mrk.height(50)
myView.mrk.width(50)
myView.mrk.center(to: view)
}
}
```### More examples:
**Edges placing**
```swift
// Create view
let myView = UIView()
myView.backgroundColor = UIColor.red
view.addSubview(myView)
// Add constraints
myView.mrk.top(to: view, attribute: .top, relation: .equal, constant: 10.0)
myView.mrk.leading(to: view, attribute: .leading, relation: .equal, constant: 10.0)
myView.mrk.trailing(to: view, attribute: .trailing, relation: .equal, constant: -10.0)
myView.mrk.bottom(to: view, attribute: .bottom, relation: .equal, constant: -10.0)
```or shorter you can omit the attributes:
```swift
myView.mrk.top(to: view, constant: 10.0)
myView.mrk.leading(to: view, constant: 10.0)
myView.mrk.trailing(to: view, constant: -10.0)
myView.mrk.bottom(to: view, constant: -10.0)
```or even shorter using `fillSuperview`:
```swift
let edgeInsets = UIEdgeInsets(top: 10.0, left: 10.0, bottom: 10.0, right: 10.0)
myView.mrk.fillSuperview(edgeInsets)
```**Centering**
```swift
myView.mrk.centerX(to: view)
myView.mrk.centerY(to: view)
```or equivalent:
```swift
myView.mrk.center(to: view)
```**Measurements**
Constraints for width and height:
```swift
myView.mrk.width(100)
myView.mrk.height(100)
```**Modify constraints**
```swift
// Create a reference to the `NSLayoutConstraint` e.g. for heightlet heightConstraint = myView.mrk.height(100)
```...
```swift
// Update the height constant
heightConstraint.constant = 30.0
// Animate changes
UIView.animate(withDuration: 0.3) {
self.view.layoutIfNeeded()
}
```## What to do next
* Writing tests
## License
MarkerKit is available under the MIT license. See the LICENSE file for more info.