easy-ios-constraint 1.0.1

easy-ios-constraint 1.0.1

Indra Tirta Nugraha 维护。



  • 作者
  • indratir

easy-ios-constraint

使用 Swift 在 iOS 中编程约束 🚀

要求

  • iOS: 11.x
  • Swift 包管理器: 5.4

安装

Swift 包管理器

Swift 包管理器是一个用于自动化 Swift 代码分配的工具,并集成到 Swift 编译器中。

一旦您的 Swift 包设置完成,将 easy-ios-constraint 添加为依赖项非常简单,只需将其添加到 Package.swift 的 dependencies 值中。

dependencies: [
    .package(url: "https://github.com/indratir/easy-ios-constraint.git", from: "1.0.0")
]

CocoaPods

CocoaPods 是 Cocoa 项目的依赖项管理器。有关使用和安装说明,请访问他们的网站。要使用 CocoaPods 将 Alamofire 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它。

pod 'Alamofire'

用法

对齐 & 填充

// Align all sides of view to superview
view.alignWithSuperview(sides: [.leading, .top, .trailing, .bottom])
// It also can be achieved using fillSuperview
view.fillSuperview()

// Align multiple sides of view to the same sides of superview with distance
view.alignWithSuperview(sides: [.leading, .trailing], distance: 20.0)
// It also can be achieved using fillSuperviewWidth
view.fillSuperviewWidth(distance: 20.0)

// Align single side of view to superview
view.alignWithSuperview(.top)

// Align single side of view to specific side of any view
subtitleLabel.align(.top, withSide: .bottom, of: titleLabel, distance: 8.0)

// Align & fill also available for safe area
view.alignWithSafeArea(sides: [.leading, .top, .trailing, .bottom])
view.alignWithSafeArea(.top)
view.fillSafeArea()

固定尺寸

// Set view's dimension with constant value
view.pinSize(128.0)
view.pinWidth(64.0)

// Set view's dimension equal to specific view
subtitleLabel.pinHeight(to: titleLabel)

// Set view's aspect ratio
// e.g: squared imageView (1:1)
imageView.pinWidth(100.0)
imageView.aspectRatio(for: .height, ratio: 1.0)

固定中心

// Set view into center of superview
view.pinCenter()

// Set view to be centerHorizontally from superview
view.pinCenterHorizontally()

// Set view to be centerVertically from any view
imageView.pinCenterVertically(to: containerView)

作者

indratir, [email protected], @indratir

许可证

easy-ios-constraint 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。