测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布上次发布 | 2017 年 5 月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
维护者magi82。
一个简单且易于使用的 API,它可以无需自动布局将绝对布局转换为相对布局。
MGRelativekit 使用方法链模式来添加视图布局。
建议使用‘apply’方法以提高性能。
view1.relativeLayout
.size(width: 100, height: 100)
.centerHorizontalSuper()
.alignSuperTop(padding: 100)
.apply()
view2.relativeLayout
.size(width: 100, height: 100)
.alignSuperRight(padding: 40)
.alignSuperBottom(padding: 40)
.apply()
view1.relativeLayout
.size(width: 100, height: 100)
.centerInSuper()
.apply()
view2.relativeLayout
.sizeOf(from: view1)
.topOf(from: view1)
.alignLeft(from: view1, padding: 30)
.apply()
view1.relativeLayout
.size(width: 200, height: 200)
.centerInSuper()
.apply()
view2.relativeLayout
.sizeOf(from: view1, margin: -100)
.centerOf(from: view1)
.apply()
// ---------------------------------------------------------------------------
// Position the current view to the left of the relative view.
func leftOf(from: UIView, margin: CGFloat = 0)
// Position the current view to the right of the relative view.
func rightOf(from: UIView, margin: CGFloat = 0)
// Position the current view to the top of the relative view.
func topOf(from: UIView, margin: CGFloat = 0)
// Position the current view to the bottom of the relative view.
func bottomOf(from: UIView, margin: CGFloat = 0)
// ---------------------------------------------------------------------------
// Position the current view to the horizontal center of the relative view.
func centerHorizontalOf(from: UIView)
// Position the current view to the vertical center of the relative view.
func centerVerticalOf(from: UIView)
// Position the current view to the center of the relative view.
func centerOf(from: UIView)
// ---------------------------------------------------------------------------
// Position the current view to the left edge of the relative view.
func alignLeft(from: UIView, padding: CGFloat = 0)
// Position the current view to the right edge of the relative view.
func alignRight(from: UIView, padding: CGFloat = 0)
// Position the current view to the top edge of the relative view.
func alignTop(from: UIView, padding: CGFloat = 0)
// Position the current view to the bottom edge of the relative view.
func alignBottom(from: UIView, padding: CGFloat = 0)
// ---------------------------------------------------------------------------
// Position the current view to the left edge of the super view.
func alignSuperLeft(padding: CGFloat = 0)
// Position the current view to the right edge of the super view.
func alignSuperRight(padding: CGFloat = 0)
// Position the current view to the top edge of the super view.
func alignSuperTop(padding: CGFloat = 0)
// Position the current view to the bottom edge of the super view.
func alignSuperBottom(padding: CGFloat = 0)
// ---------------------------------------------------------------------------
// Position the current view to the horizontal center of the super view.
func centerHorizontalSuper()
// Position the current view to the vertical center of the super view.
func centerVerticalSuper()
// Position the current view to the center of the super view.
func centerInSuper()
// ---------------------------------------------------------------------------
// Apply the same size as the super view.
func sizeOfSuper(margin: CGFloat = 0)
// Apply the same size as the relative view.
func sizeOf(from: UIView, margin: CGFloat = 0)
// Apply custom size to the current view.
func size(width: CGFloat, height: CGFloat)
// Apply the same width size as the super view.
func widthOfSuper()
// Apply the same width size as the relative view.
func widthOf(from: UIView)
// Apply custom width size to the current view.
func width(_ width: CGFloat)
// Apply the same height size as the super view.
func heightOfSuper()
// Apply the same height size as the relative view.
func heightOf(from: UIView)
// Apply custom height size to the current view.
func height(_ height: CGFloat)
// ---------------------------------------------------------------------------
// Finalize the changed layout to the current view.
func apply()
pod 'MGRelativeKit'
github "magi82/MGRelativeKit"
magi82, [email protected]
MGRelativeKit 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。