RacoonKit 1.0.0

RacoonKit 1.0.0

Behran Kankul 维护。



RacoonKit 1.0.0

  • behrank

CI Status Version License Platform

RacoonKit

RacoonKit 是 iOS 平台的布局 API。RacoonKit 使用 Swift 4 开发,并使用 Apple Visual Format Language 和 NSLayoutConstraint SDK。

请参阅这篇文章了解 AVF 的更多信息 => https://www.raywenderlich.com/277-auto-layout-visual-format-language-tutorial

CocoaPods 安装

将 RacoonKit 添加到 pod 文件。

pod 'RacoonKit'

然后在项目文件夹中通过终端运行 pod install 命令。

pod install

使用方法

添加子视图

您可以像数组一样将任何基于 UIView 的组件添加到容器视图中。

let newView = UIView()
let otherNewView = UIView()
view.addSubviews(views: newView, otherNewView)

放置视图

使用数组在一行中定义视图的边距

let newView = UIView()
newView.setMargins(.top(value: 8), .left(value: 8), .right(value: 8), .bottom(value: 8))

定义两个视图之间的边距

newView.setMarginTo(view: otherNewView, of: .top(value: 8))
newView.setMarginTo(view: otherNewView, of: .right(value: 8))
newView.setMarginTo(view: otherNewView, of: .left(value: 8))
newView.setMarginTo(view: otherNewView, of: .bottom(value: 8))

高度和宽度

newView.setHeight(100)
newView.setWidth(125)
newView.setWidthEqualToSuperview()
newView.setHeightEqualToSuperview()
newView.setWidthEqualTo(view: view)
newView.setHeightEqualTo(view: view)
newView.setWidthEqualTo(views: view, view, view)
newView.setHeightEqualTo(views: view, view, view)

将 'Equal' 和 'Priority' 设置为约束

使用新的 RacoonFormat,您可以定义优先级和相等属性。使用 setMarginWith(formats: RacoonFormat...) 方法定义多个约束。

firstView.setMarginWith(formats: RacoonFormat(constant: .top(value: 0)))
firstView.setMarginWith(formats: RacoonFormat(constant: .left(value: 10), equality: RacoonEquality.greaterOrEqual))
firstView.setMarginWith(formats: RacoonFormat(constant: .right(value: 20), equality: RacoonEquality.lessOrEqual, priority: RacoonPriority.high))

使用 RacoonFormat 设置两个视图之间的关系

firstView.setMarginTo(view: secondView, with: RacoonFormat(constant: .top(value: 0)))
firstView.setMarginTo(view: secondView, with: RacoonFormat(constant: .left(value: 10), equality: RacoonEquality.greaterOrEqual))
firstView.setMarginTo(view: secondView, with: RacoonFormat(constant: .right(value: 20), equality: RacoonEquality.lessOrEqual, priority: RacoonPriority.high))

贡献

欢迎提交拉取请求。对于重大更改,请先打开一个问题来讨论您想进行更改的内容。

许可协议

MIT