VDPin

CI Status Version License Platform

描述

此仓库提供了一些方便创建约束的方法。

用法

  1. 将视图的属性固定到指定的项目或其父视图。
view.pin(.edges)
view.pin(.leading)
view.pin(.edges(.horizontal), 16)
view.pin(edges(.top, .bottom), 10, to: safeAreaLayoutGuide)
view.pin(edges: [.top: 10, .horizontal: 5], to: safeAreaLayoutGuide)
// pin view after/before another view
rightView.pin(to: .trailing, of: leftView, options: .offset(10))
view.pin(.center, 10)
view.pin([.size: 100, .centerY: 10, .top: 20, .edges(.horizontal): 10])
  1. 固定两个视图之间的任何属性
view.pin(.top, to: .centerY, of: anotherView)
  1. 设置视图的宽高比。
view.pin(aspectRatio: 2 / 3)
  1. 所有 pin 方法都包含一个 with options 参数。
view.pin(.edges, 10, options: .priority(.required))

选项

  1. 所有这些方法都可以链式调用
view
    .pin(.edges(.horizontal), 10)
    .pin(to: .bottom, of: anotherView.pin(.height, 50), options: .offset(20))
    .pin(.size, 100)
  1. 使用 PartialRangeThroughPartialRangeFrom 用于偏移量值
view.pin(.bottom, 10..., with: .safeArea)
view.pin(to: .bottom, of: anotherView, options: .offset(...10))
  1. 所有这些方法都返回 Constraints 对象,可用于更新约束。

安装

  1. Swift Package Manager

创建一个 Package.swift 文件。

// swift-tools-version:5.7
import PackageDescription

let package = Package(
  name: "SomeProject",
  dependencies: [
    .package(url: "https://github.com/dankinsoid/VDPin.git", from: "1.7.0")
  ],
  targets: [
    .target(name: "SomeProject", dependencies: ["VDPin"])
  ]
)
$ swift build
  1. CocoaPods

将以下行添加到您的 Podfile

pod 'VDPin'

并首先从 podfile 目录运行 pod update

作者

dankinsoid, voidilov@gmail.com

许可证

VDPin 在 MIT 许可证下可用。 有关更多信息,请参见 LICENSE 文件。