{"id":1278,"url":"https://github.com/fhisa/SwiftyLayout","last_synced_at":"2025-07-30T20:33:03.530Z","repository":{"id":96586612,"uuid":"40695785","full_name":"fhisa/SwiftyLayout","owner":"fhisa","description":"Lightweight declarative auto-layout framework for Swift","archived":false,"fork":false,"pushed_at":"2017-02-19T23:23:00.000Z","size":130,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-14T14:06:29.236Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fhisa.png","metadata":{"files":{"readme":"README-ja.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-08-14T04:30:30.000Z","updated_at":"2017-11-07T04:58:40.000Z","dependencies_parsed_at":"2023-03-18T05:00:22.438Z","dependency_job_id":null,"html_url":"https://github.com/fhisa/SwiftyLayout","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fhisa%2FSwiftyLayout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fhisa%2FSwiftyLayout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fhisa%2FSwiftyLayout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fhisa%2FSwiftyLayout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fhisa","download_url":"https://codeload.github.com/fhisa/SwiftyLayout/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228187620,"owners_count":17882335,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:15:42.794Z","updated_at":"2024-12-04T20:31:12.019Z","avatar_url":"https://github.com/fhisa.png","language":"Swift","funding_links":[],"categories":["Layout","Libs"],"sub_categories":["Other Hardware","Other free courses","Layout"],"readme":"# SwiftyLayout\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/fhisa/SwiftyLayout/master/LICENSE)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![GitHub release](https://img.shields.io/github/release/fhisa/SwiftyLayout.svg)](https://github.com/fhisa/SwiftyLayout/releases)\n[![build passing](https://travis-ci.org/fhisa/SwiftyLayout.png?branch=master)](https://travis-ci.org/fhisa/SwiftyLayout)\n\n[![Join the chat at https://gitter.im/fhisa/SwiftyLayout](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/fhisa/SwiftyLayout?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nSwiftyLayout は、Swiftプログラムにおいて、レイアウト制約(NSLayoutConstraint)を簡単な数式として定義できるようにするフレームワークです。\n\n## バージョンについて\n\n- SwiftyLayout 3 は Swift 2 用です。\n- SwiftyLayout 4 は Swift 3 用です。\n\n\n## コード例\n\n### 基本的な使い方\n「ビューAの横幅はビューBの横幅の50%から4.0引いたものと等しい」というレイアウト制約は、SwiftyLayoutフレームワークを使って:\n```swift\nviewA[.Width] == 0.5 * viewB[.Width] - 4.0\n```\nのように記述できます。これは以下のコードと同じレイアウト制約を生成します:\n```swift\nNSLayoutConstraint(\n    item: viewA, attribute: .Width,\n    relatedBy: .Equal,\n    toItem: viewB, attribute: .Width,\n    multiplier: 0.5, constant: -4.0)\n```\n\n### 例)アスペクト比\nまた「ビューAのサイズの縦横比は 3:4 に等しい」という制約は:\n```swift\nviewA[.Width] * 3.0 == viewA[.Height] * 4.0\n```\nのように記述できます。これは以下のコードと同じレイアウト制約を生成します:\n```swift\nNSLayoutConstraint(\n    item: viewA, attribute: .Width,\n    relatedBy: .Equal,\n    toItem: viewA, attribute: .Height,\n    multiplier: 4.0/3.0, constant: 0.0)\n```\n\n### 例)優先順位の指定\n\n二項演算子`~`を使ってレイアウト制約の優先順位を指定することができます:\n```swift\ninnerView[.Leading] == outerView[.Leading] + 4.0 ~ 750.0\n```\nこの演算子は、レイアウト制約の優先順位を設定した上でそのレイアウト制約を返します:\n```swift\nvar constraint = NSLayoutConstraint(\n    item: innerView, attribute: .Leading,\n    relatedBy: .Equal,\n    toItem: outerView, attribute: .Leading,\n    multiplier: 1.0, constant: 4.0)\nconstraint.priority = 750.0\n// -\u003e constraint\n```\n\n[サンプルアプリ](https://github.com/fhisa/SwiftyLayout/blob/master/SampleApp/ViewController.swift)や[テストケース](https://github.com/fhisa/SwiftyLayout/blob/master/SwiftyLayoutTests/SwiftyLayoutTests.swift)のコードも参考にしてください。\n\n## リファレンスガイド\n\n### 制約項 (ConstraintTerm)\n\n制約項(ConstraintTerm)とは、レイアウト制約の右辺または左辺で、ビューを含む項のことです。\nあるビュー`viewA`の横幅`.Width`を表す制約項は:\n```swift\nviewA[.Width]\n```\nと記述します。`viewA`のところにはUIViewオブジェクトが、`.Width`のところには`NSLayoutAttribute`型の値が入ります。\n制約項は、以下のような構造体として定義されています:\n```swift\npublic struct ConstraintTerm\n{\n    let view: UIView?\n    let attribute: NSLayoutAttribute\n    var multiplier: CGFloat = 1.0\n    var constant: CGFloat = 0.0\n}\n```\n\n### 演算子\n\n*以下の表で「制約項」は`ConstraintTerm`型の値、「定数」は`CGFloat`型の値、「レイアウト制約」は`NSLayoutConstraint`オブジェクトを表します。*\n\n| 演算子 | 左辺 | 右辺 | 評価値 | 意味 |\n|:-----:|:------|:------|:-------|:--|\n| +     | 制約項 | 定数   | 制約項 | 左辺の`constant`に右辺の値を加算 |\n| +     | 定数   | 制約項 | 制約項 | 右辺の`constant`に左辺の値を加算 |\n| -     | 制約項 | 定数   | 制約項 | 左辺の`constant`から右辺の値を減算 |\n| *     | 制約項 | 定数   | 制約項 | 左辺の`multiplier`と`constant`に右辺の値を乗算 |\n| *     | 定数   | 制約項 | 制約項 | 右辺の`multiplier`と`constant`に左辺の値を乗算 |\n| /     | 制約項 | 定数   | 制約項 | 左辺の`multiplier`と`constant`を右辺の値で除算 |\n| ==    | 制約項 | 制約項 | レイアウト制約 | 「左辺と右辺の値が等しい」というレイアウト制約を生成 |\n| ==    | 制約項 | 定数   | レイアウト制約 | 同上 |\n| ==    | 定数   | 制約項 | レイアウト制約 | 同上 |\n| \u003c=    | 制約項 | 制約項 | レイアウト制約 | 「左辺の値は右辺の値より小さいか等しい」というレイアウト制約を生成 |\n| \u003c=    | 制約項 | 定数   | レイアウト制約 | 同上 |\n| \u003c=    | 定数   | 制約項 | レイアウト制約 | 同上 |\n| \u003e=    | 制約項 | 制約項 | レイアウト制約 | 「左辺の値は右辺の値より大きいか等しい」というレイアウト制約を生成 |\n| \u003e=    | 制約項 | 定数   | レイアウト制約 | 同上 |\n| \u003e=    | 定数   | 制約項 | レイアウト制約 | 同上 |\n| ~     | レイアウト制約 | 定数(Float型) | レイアウト制約 | レイアウト制約の優先度を変更して、そのレイアウト制約を返す |\n\n## Requirements\n\n- Swift 2.0 (Xcode 7 以降)\n- iOS 8 以降 / iOS 7 (ソースコードを直接コピー)\n- iOS\n  - iOS 8 以降 / iOS 7 (ソースコードを直接コピー)\n- Mac\n  - Mac OS X 10.10 以降 / 10.9 以前での動作は不明\n\n## インストール\n\n2種類の方法があります。\n\n### Carthage を使ってインストール\n\nSwiftyLayout は [Carthage](https://github.com/Carthage/Carthage) を使うと簡単にプロジェクトに追加できます。\n\n- Cartfile に `github \"fhisa/SwiftyLayout\"` の1行を追加\n- `carthage update` を実行\n- Carthage/Build の中にできたフレームワークをプロジェクトに追加\n\n### ソースファイルを直接コピー (iOS 7)\n\n- Add this repository as a git submodule:\n```shell\n$ git submodule add https://github.com/fhisa/SwiftyLayout.git PATH_TO_SUBMODULE\n// or\n$ carthage update --use-submodules\n```\n- Then just add references of SwiftyLayout/*.swift to your Xcode project.\n\n## TODO\n\n- [CocoaPods](https://cocoapods.org) 対応\n\n## ライセンス\n\nSwiftyLayout は [MIT license](https://github.com/fhisa/SwiftyLayout/blob/master/LICENSE) の元で配布しています。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffhisa%2FSwiftyLayout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffhisa%2FSwiftyLayout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffhisa%2FSwiftyLayout/lists"}