WHCustomizeConstraint 0.1.2

WHCustomizeConstraint 0.1.2

Wajahat Hassan 维护。



  • 作者:
  • wajahathassan64

WHCustomizeConstraint

CI Status Version License Platform

特性

  • Swift 5 糖衣。
  • 以更短的方式执行 Auto Layout 的所有操作。
  • 默认情况下约束为活动状态。
  • 与其他 Auto Layout 代码兼容。
  • 在创建时设置约束优先级。
  • 直接约束到父视图。

安装

WHCustomizeConstraint 通过 CocoaPods 提供使用。要安装它,只需将以下行添加到您的 Podfile 中

pod 'WHCustomizeConstraint'

示例

要运行示例项目,克隆仓库,并在 Example 目录下运行 pod install。另外,以下有一些有用的示例。

调整边缘

使用 NSLayoutConstraint 将任何 UI 组件 连接到其父视图

NSLayoutConstraint.activate([
view.topAnchor.constraint(equalTo: superview.topAnchor, constant: 0),
view.leadingAnchor.constraint(equalTo: superview.leadingAnchor, constant: 0),
view.bottomAnchor.constraint(equalTo: superview.bottomAnchor, constant: 0),
view.trailingAnchor.constraint(equalTo: superview.trailingAnchor, constant: 0)
])

使用 WHCustomizeConstraint

view.alignAllEdgesWithSuperview()

或者

view.alignEdgesWithSuperview([.left, .right, .top, .bottom], constants: [0,0,0,0]) 

在父视图中居中

使用 NSLayoutConstraint 将视图 (UI 组件) 定位于其父视图的中心

NSLayoutConstraint.activate([
view.centerXAnchor.constraint(equalTo: superview.centerXAnchor, constant: 0)
view.centerYAnchor.constraint(equalTo: superview.centerYAnchor, constant: 0)
])

使用 WHCustomizeConstraint

view.centerInSuperView()

用法

与父视图一起添加约束

在父视图中水平居中

使用 WHCustomizeConstraint 将视图 水平 约束于其父视图的中心

view.centerHorizontallyInSuperview()

在父视图中垂直居中

使用 WHCustomizeConstraint 将视图 垂直 约束于其父视图的中心

view.centerVerticallyInSuperview()

边缘父视图安全区域

使用 WHCustomizeConstraint 将具有边距的视图附加到上视图的SafeArea

view.alignEdgeWithSuperviewSafeArea(.top, constant: 10)

从顶部到底部 & 从底部到顶部

这些约束将 secondView 的顶部锚点约束到 firstView 的底部锚点

secondView.topToBottom(firstView)
or
secondView.topToBottom(firstView, constant: 10)

这些约束将 firstView 的底部锚点约束到 secondView 的顶部锚点

firstView.bottomToTop(secondView)
or
firstView.bottomToTop(secondView, constant: 10)

作者

wajahathassan64, [email protected]

许可

WHCustomizeConstraint 在MIT许可下可用。有关更多信息,请参阅LICENSE文件。