Swiftpack.co - Package - SnapKit/SnapKit

SnapKit is a DSL to make Auto Layout easy on both iOS and OS X.

Build Status Platform Cocoapods Compatible Carthage compatible

⚠️ To use with Swift 4.x please ensure you are using >= 4.0.0 ⚠️

⚠️ To use with Swift 5.x please ensure you are using >= 5.0.0 ⚠️

Contents

Requirements

  • iOS 10.0+ / Mac OS X 10.12+ / tvOS 10.0+
  • Xcode 10.0+
  • Swift 4.0+

Communication

  • If you need help, use Stack Overflow. (Tag 'snapkit')
  • If you'd like to ask a general question, use Stack Overflow.
  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Installation

CocoaPods

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

$ gem install cocoapods

CocoaPods 1.1.0+ is required to build SnapKit 4.0.0+.

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

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

target '<Your Target Name>' do
    pod 'SnapKit', '~> 5.0.0'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

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

github "SnapKit/SnapKit" ~> 5.0.0

Run carthage update to build the framework and drag the built SnapKit.framework into your Xcode project.

Manually

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


Usage

Quick Start

import SnapKit

class MyViewController: UIViewController {

    lazy var box = UIView()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.addSubview(box)
        box.backgroundColor = .green
        box.snp.makeConstraints { (make) -> Void in
           make.width.height.equalTo(50)
           make.center.equalTo(self.view)
        }
    }

}

Playground

You can try SnapKit in Playground.

Note:

To try SnapKit in playground, open SnapKit.xcworkspace and build SnapKit.framework for any simulator first.

Resources

Credits

License

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

Github

link
Stars: 16706

Dependencies

Used By

Total: 0

Releases

SnapKit 5.0.1 - 2019-08-05 06:21:35

  • Fixes a regression caused by #574
  • Adds Playground #608 (thanks to @ShivaHuang)
  • Updates SwiftPM support #615 (thanks to @maxxfrazer)
  • Adds .directionalEdges and .directionalMargins #595 (thanks to @jctrouble)
  • Make ConstraintViewDSL content priorities non mutational #586 (thanks to @nekrich)

Swift 5.0.0 - 2019-04-23 11:01:46

• Official support for Swift 5.0 • Min version is now iOS 10.0, tvOS 10.0 and macOS 10.12

SnapKit 4.2.0 - 2018-10-22 12:16:01

  • Official Swift 4.2 compatibility release

SnapKit 4.0.1 - 2018-09-18 04:40:18

  • Compatibility with Xcode 10

Swift 4 + Xcode 9 - 2017-09-17 03:04:21

This is a compatibility release to target Swift 4 and Xcode 9. It contains no new features only syntax changes required for Swift 4 and Xcode 9!

Bug fixes & Priorities - 2017-02-11 10:18:28

  • Added isActive to Constraint so you can see if there are any active NSLayoutConstraint's that are currently active as a result of the backing constraint.
  • Made Constraint layoutConstraints public again so you can publicly access the layout constraints. Use with caution as SnapKit expects ownership of these.
  • Fixed bug with contentCompressionResistanceHorizontalPriority (#387)
  • Fixed missing topMargin with contentCompressionResistanceHorizontalPriority (#393)
  • Added more robust priority support (#345)

Maker for Guides - 2016-10-07 11:21:30

ConstraintMaker for UILayoutGuide's

  • You can now use a UILayoutGuide/NSLayoutGuide much like a UIView with the familiar makeConstraints, remakeConstraints, updateConstraints, and removeConstraints API.

Bug Fixes

  • Fixed memory leaks and circular references

More Bug Fixes - 2016-10-07 11:12:57

Bug Fixes

  • Fix Carthage build compatibility
  • Adds topMargin back in to ConstraintMaker
  • Adds equalToSuperview(), lessThanOrEqualToSuperview(), greaterThanOrEqualToSuperview()
  • Doing equalTo(CGPoint) ensures superview + offset from top left.

Swift 2.3 - 2016-09-20 05:26:58

A tagged release for Swift 2.3!

Mostly Bug Fixes - 2016-09-20 05:20:57

Breaking Changes

  • Debug labels must now use a function rather than a property. snp.label = "" is now snp.setLabel("")

Bug Fixes

  • Fixed small memory leaks on all constraints #310
  • Fixed macOS bug preventing make.edges.equalTo(other.snp.edges) #309
  • Fixed bug preventing debug labels from being set. You must now use setLabel() #313
  • Fixed incorrect constant values when using leading/trailing and UIEdgeInsets #316

SnapKit 3.0.0 - Swift 3.0 Release - 2016-09-20 05:16:32

SnapKit 3.0 is a complete re-write to take advantage of modern Swift 3.0 as well as clean up the API. As such please use with caution and check your apps thoroughly

Breaking

  • iOS 7.0 support has been removed
  • install and uninstall have been deprecated, use activate and deactivate instead
  • DSL is now accessed through .snp.* rather than .snp_*. For example view.snp.makeConstraints { }
  • Constraints are now updated through update(offset:), update(inset:) and update(priority:)
  • .inset() will no longer take CGPoint or CGSize as input
  • .offset() will no longer take CGPoint, CGSize, EdgeInsets as input
  • updateConstraints will no longer allow creating new constraints unless there are no existing constraints for the view. If it does generate new constraints it will throw a fatal error.
  • UIEdgeInsets are now have their right and bottom value inverted for more natural results such as make.edges.equalTo(UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)).inset()

Enhancements

  • Debugging output has been improved to show exact file/line number from which the broken constraint was created
  • Exceptions thrown during constraint creation have been replaced with fatalError with better output
  • Constraints are now installed through NSLayoutConstraint.activate and what view they are added to is now deferred to UIKit
  • Added var contentHugging<Axis>Priority: CGFloat to make
  • Added var contentCompressionResistance<Axis>Priority: CGFloat to make
  • Added support for UILayoutGuide via make.left.equalTo(guide.snp.top)
  • Added support for constraining edges to margins or vice versa via make.edges.equalTo(other.snp.margins)