MarkerKit 1.4.0

MarkerKit 1.4.0

Michael Pchelnikov 维护。



MarkerKit 1.4.0

MarkerKit

MarkerKit

一个轻量且易于使用的 Auto Layout Constraints(iOS 8+ 支持)包装器,灵感来源于 https://github.com/ustwo/autolayout-helper-swift

License Platform Cocoapods Compatible Carthage compatible

需求

  • iOS 8.0+
  • Xcode 10.2+
  • Swift 5.0+

安装

CocoaPods

您可以使用 CocoaPods

platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
  pod 'MarkerKit'
end

Carthage

您可以使用 Carthage。在 Cartfile 中指定。

github "pchelnikov/MarkerKit"

运行 carthage 来构建框架,并将构建好的 MarkerKit.framework 拖入您的 Xcode 项目中。请参阅构建说明

手动

  • MarkerKit.swift 文件添加到您的 Xcode 项目中。

使用方法

快速入门

import MarkerKit

class MyViewController: UIViewController {

    lazy var myView = UIView()

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(myView)
        
        myView.mrk.height(50)
        myView.mrk.width(50)
        myView.mrk.center(to: view)
    }
}

更多示例

边缘放置

// Create view
    
let myView = UIView()
myView.backgroundColor = UIColor.red
view.addSubview(myView)
    
// Add constraints
    
myView.mrk.top(to: view, attribute: .top, relation: .equal, constant: 10.0)
myView.mrk.leading(to: view, attribute: .leading, relation: .equal, constant: 10.0)
myView.mrk.trailing(to: view, attribute: .trailing, relation: .equal, constant: -10.0)
myView.mrk.bottom(to: view, attribute: .bottom, relation: .equal, constant: -10.0)

或者更短,可以省略属性

myView.mrk.top(to: view, constant: 10.0)
myView.mrk.leading(to: view, constant: 10.0)
myView.mrk.trailing(to: view, constant: -10.0)
myView.mrk.bottom(to: view, constant: -10.0)

甚至更短,使用 fillSuperview

let edgeInsets = UIEdgeInsets(top: 10.0, left: 10.0, bottom: 10.0, right: 10.0)
myView.mrk.fillSuperview(edgeInsets)

居中

myView.mrk.centerX(to: view)
myView.mrk.centerY(to: view)

或者等效的

myView.mrk.center(to: view)

度量

宽度和高度的约束

myView.mrk.width(100)
myView.mrk.height(100)

修改约束

// Create a reference to the `NSLayoutConstraint` e.g. for height

let heightConstraint = myView.mrk.height(100)

...

// Update the height constant

heightConstraint.constant = 30.0

// Animate changes

UIView.animate(withDuration: 0.3) {
    self.view.layoutIfNeeded()
}

接下来做什么

  • 编写测试

许可协议

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