📱 📐 约束
轻量级的约束制作工具
需求
- iOS 9.0或更高版本
- Xcode 10.0或更高版本
安装
有一种方法可以在您的项目中使用约束
- 使用CocoaPods
使用CocoaPods安装
pod 'TheConstraints'
构建项目
到此为止,您的工作区应该可以无错误地构建。如果您遇到问题,请发布至问题记录,社区可以帮您解决。
如何使用
import TheConstraints
view.addSubview(subView)
位置
subView.leading == view.leading
subView.trailing == view.trailing
subView.top == view.top - 100
subView.bottom == view.bottom + 100
大小
subView.width == 50
subView.width == view.width + 100
subView.width == view.width * 2
subView.height == 100
subView.height == view.height - 200
subView.height == view.height / 2
中心
subView.centerX == view.centerX + 100
subView.centerY == view.centerY - 200
subView.mid == view.mid // centerX & centerY
边缘
subView.edges == view.edges // top & trailing & bottom & leading
subView.edges == inset(view.edges, 8) // as `UIEdgeInsets(top: 8, left: 8, bottom: -8, right: -8)`
subView.edges == inset(view.edges, horizontal: 8) // as `UIEdgeInsets(top: 0, left: 8, bottom: 0, right: -8)`
subView.edges == inset(view.edges, vertical: 4) // as `UIEdgeInsets(top: 4, left: 0, bottom: -4, right: 0)`
subView.edges == inset(view.edges, horizontal: 8, vertical: 4) // as `UIEdgeInsets(top: 4, left: 8, bottom: -4, right: -8)`
subView.edges == inset(view.edges, insets: UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8)) // as `UIEdgeInsets(top: 4, left: 8, bottom: -4, right: -8)`
更新
let bottomConstraint = subView.bottom == view.bottom
bottomConstraint.constant = 100
作者
沟通
- 如果您找到了一个错误,请打开一个问题。
- 如果您有功能请求,请打开一个问题。
- 如果您想贡献力量,请提交一个拉取请求。
许可证
所有源代码均受MIT许可证许可。