MGRelativeKit 0.1.4

MGRelativeKit 0.1.4

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2017 年 5 月
SwiftSwift 版本3.0
SPM支持 SPM

维护者magi82



  • magi82

MGRelativeKit

一个简单且易于使用的 API,它可以无需自动布局将绝对布局转换为相对布局。☀️

MGRelativekit 使用方法链模式来添加视图布局。
建议使用‘apply’方法以提高性能。

使用示例

  • 示例 1
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()

  • 示例 2
view1.relativeLayout
  .size(width: 100, height: 100)
  .centerInSuper()
  .apply()
  
view2.relativeLayout
  .sizeOf(from: view1)
  .topOf(from: view1)
  .alignLeft(from: view1, padding: 30)
  .apply()

  • 示例 3
view1.relativeLayout
  .size(width: 200, height: 200)
  .centerInSuper()
  .apply()
  
view2.relativeLayout
  .sizeOf(from: view1, margin: -100)
  .centerOf(from: view1)
  .apply()

API 参考

// ---------------------------------------------------------------------------

// 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()

要求

  • Swift 3.0+
  • Xcode 8.0+
  • iOS 8.0+

安装

  • 对于 iOS 8+ 的项目 使用 CocoaPods
pod 'MGRelativeKit'
  • 对于 iOS 8+ 的项目 使用 Carthage
github "magi82/MGRelativeKit"

作者

magi82, [email protected]

许可证

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