SimpleLayout 0.2.1

SimpleLayout 0.2.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2016年11月
SwiftSwift 版本3.0
SPM支持 SPM

Nicolas Molina 维护。




  • 作者:
  • Nicolas Molina

SimpleLayout

Índice

功能

  • 易于使用
  • NSLayoutConstraint 短路

屏幕截图

Demo Example

先决条件

  • iOS 8+
  • Xcode 7+
  • Swift 3.0

如何使用

查看演示项目以获取具体示例。

示例

let background = UIView()

background.backgroundColor = .greenColor()
view.addSubview(background)

SimpleLayout.addMarginZero(background, toItem: view)
// OR
// background.sl_addMarginZero(view)
// OR
// background.sl_addMargin(view, constant: 0)

API

边距
let imgProfile = UIImageView()

imgProfile.image = UIImage(named: "yourimage")
view.addSubview(imgProfile)

SimpleLayout.addMarginTop(imgProfile, toItem: view, constant: 10)
SimpleLayout.addMarginLeft(imgProfile, toItem: view, constant: 10)
SimpleLayout.addMarginRight(imgProfile, toItem: view, constant: 10)
// OR
// imgProfile.sl_addMarginTop(view, constant: 10)
// imgProfile.sl_addMarginLeft(view, constant: 10)
// imgProfile.sl_addMarginRight(view, constant: 10)
// OR
// imgProfile.sl_addMarginTop(view, constant: 10)
// imgProfile.sl_addMarginLeading(view, constant: 10)
// imgProfile.sl_addMarginTrailing(view, constant: 10)
let lblFooter = UILabel()

lblFooter.text = "Copyright © 2016 YourApp. All rights reserved"
view.addSubview(lblFooter)

SimpleLayout.addMarginBottom(lblFooter, toItem: view, constant: 10)
SimpleLayout.addMarginLeft(lblFooter, toItem: view, constant: 10, relatedBy: .GreaterThanOrEqual)
SimpleLayout.addMarginRight(lblFooter, toItem: view, constant: 10, relatedBy: .GreaterThanOrEqual)
// OR
// lblFooter.sl_addMarginBottom(view, constant: 10)
// lblFooter.sl_addMarginLeft(view, constant: 10, relatedBy: .GreaterThanOrEqual)
// lblFooter.sl_addMarginRight(view, constant: 10, relatedBy: .GreaterThanOrEqual)
// OR
// lblFooter.sl_addMarginBottom(view, constant: 10)
// lblFooter.sl_addMarginLeading(view, constant: 10, relatedBy: .GreaterThanOrEqual)
// lblFooter.sl_addMarginTrailing(view, constant: 10, relatedBy: .GreaterThanOrEqual)
原点
let lblName = UILabel()

lblName.text = "Pepito"
view.addSubview(lblName)

SimpleLayout.addCenter(lblName, toItem: view)
// OR
// lblName.sl_addCenter(view)
let lblFooter = UILabel()

lblFooter.text = "Copyright © 2016 YourApp. All rights reserved"
view.addSubview(lblFooter)

SimpleLayout.addCenterX(lblFooter, toItem: view)
SimpleLayout.addMarginBottom(lblFooter, toItem: view, constant: 10)
// OR
// lblFooter.sl_addCenterX(view)
// lblFooter.sl_addMarginBottom(view, constant: 10)
大小
let lblDescription = UILabel()

lblDescription.text = "Description to long..."
lblDescription.lineBreakMode = NSLineBreakMode.ByWordWrapping
lblDescription.numberOfLines = 0 // Infinite
view.addSubview(lblDescription)

SimpleLayout.addHeight(lblDescription, constant: 21, relatedBy: .GreaterThanOrEqual)
// OR
// lblDescription.sl_addHeight(21, relatedBy: .GreaterThanOrEqual)
let imgProfile = UIImageView()

imgProfile.image = UIImage(named: "yourimage")
view.addSubview(imgProfile)

SimpleLayout.addSize(imgProfile, constant: 175)
SimpleLayout.addCenter(imgProfile, toItem: view)
// OR
// imgProfile.sl_addSize(175)
// imgProfile.sl_addCenter(view)

许可证

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