SnapKit - A Swift Autolayout DSL for iOS & OS X

(A Swift Autolayout DSL for iOS & OS X)

Created at: 2014-06-06 05:13:40
Language: Swift
License: MIT

SnapKit は、iOS と OS X の両方で自動レイアウトを簡単にするための DSL です。

ビルドステータス プラットホーム ココアポッド互換 カルタゴ対応

⚠️Swift 4.xで使用するには、>= 4.0.0⚠️を使用していることを確認してください

⚠️Swift 5.xで使用するには、>= 5.0.0⚠️を使用していることを確認してください

内容

必要条件

  • iOS 10.0+ / Mac OS X 10.12+ / tvOS 10.0+
  • Xcode 10.0+
  • スウィフト 4.0+

移行ガイド

通信

  • ヘルプが必要な場合はスタックオーバーフローを使用してください。(タグ 'スナップキット')
  • 一般的な質問をしたい場合は、スタックオーバーフローを使用してください。
  • バグが見つかった場合は、問題を開きます。
  • 機能リクエストがある場合は、問題をオープンします。
  • 貢献したい場合は、プルリクエストを送信します。

取り付け

ココアポッド

CocoaPodsは Cocoa プロジェクトの依存関係マネージャーです。次のコマンドでインストールできます。

$ gem install cocoapods

SnapKit 4.0.0+ をビルドするには、CocoaPods 1.1.0+ が必要です。

CocoaPods を使用して SnapKit を Xcode プロジェクトに統合するには、以下で指定します。

Podfile

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

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

次に、次のコマンドを実行します。

$ pod install

カルタゴ

Carthageは、依存関係を構築し、バイナリフレームワークを提供する分散型依存関係マネージャーです。

次のコマンドを使用して、自作でカルタゴをインストールできます。

$ brew update
$ brew install carthage

Carthageを使用してSnapKitをXcodeプロジェクトに統合するには、次の方法で指定します。

Cartfile

github "SnapKit/SnapKit" ~> 5.0.0

Run

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

Swift Package Manager

Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

Xcode 11+ is required to build SnapKit using Swift Package Manager.

To integrate SnapKit into your Xcode project using Swift Package Manager, add it to the dependencies value of your

Package.swift
:

dependencies: [
    .package(url: "https://github.com/SnapKit/SnapKit.git", .upToNextMajor(from: "5.0.1"))
]

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.