Skip to content

LayoutKit is a DSL to make Auto Layout easy for iOS

License

Notifications You must be signed in to change notification settings

lucabelezal/LayoutKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LayoutKit

Carthage compatible CocoaPods compatible Travis

LayoutKit is a DSL to make Auto Layout easy iOS

Requirements

  • iOS 9.0+
  • Xcode 10.0+
  • Swift 4.2+

Installation

CocoaPods - Coming Soon 😔

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate LayoutKit into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

pod 'LayoutKit', '~> 1.0.0'

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate LayoutKit into your Xcode project using Carthage, specify it in your Cartfile:

github "viniciusfranca/LayoutKit" ~> 1.0.0

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate LayoutKit into your project manually.

Embedded Binaries

  • Download the latest release from https://github.com/viniciusfranca/LayoutKit/releases
  • Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
  • In the tab bar at the top of that window, open the "General" panel.
  • Click on the + button under the "Embedded Binaries" section.
  • Add the downloaded LayoutKit.framework.
  • And that's it!

Usage

Quick Start

import LayoutKit

class MyViewController: UIViewController {

    lazy var box = UIView()
    private var constraintReference: NSLayoutConstraint?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        /** addView method set box with 
          * translatesAutoresizingMaskIntoConstraints = false 
          * and addSubview
          */
        self.view.addView(box)

        box.layout.makeConstraints { make in
            make.top.equalTo(self.view.layout.top)
            // .reference() method guard reference constraint
            make.left.equalTo(self.view.layout.left).reference(&constraintReference)
            // .priority() method set priority in constraint
            make.right.equalTo(self.view.layout.right).priority(.medium)
            // .insetSafeArea() sum safeAreaInsets in constraint
            make.height.equalTo(constant: 100).insetSafeArea(.top)
        }

    }

}

Contributing

Issues and pull requests are welcome :D

License

LayoutKit is released under the MIT license. See LICENSE for details.