ComputableLayout 0.7.0

ComputableLayout 0.7.0

Dominic Go 维护。



ComputableLayout

基于配置的布局计算器。

ComputaleLayoutTestPresets



安装

Cocoapods

ComputableLayout 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile

pod 'ComputableLayout'

Swift Package Manager (SPM)

方法:#1:通过 Xcode GUI

  1. 文件 > Swift Packages > 添加包依赖
  2. 添加 https://github.com/dominicstop/ComputableLayout.git

方法:#2:通过 Package.swift

  • 打开您的项目中的 Package.swift 文件。
  • Package.swift 中更新 dependencies,并添加以下内容
dependencies: [
  .package(url: "https://github.com/dominicstop/ComputableLayout.git",
  .upToNextMajor(from: "0.1.0"))
]



基本用法

🔗 完整示例

import UIKit
import ComputableLayout


class ViewControllerBasicUsage01: UIViewController {

  var layoutConfig = ComputableLayout(
    horizontalAlignment: .center,
    verticalAlignment: .center,
    width: .constant(100),
    height: .constant(100)
  );
  
  var layoutContext: ComputableLayoutValueContext? {
    ComputableLayoutValueContext(fromTargetViewController: self);
  };
  
  var floatingView: UIView?;

  override func viewDidLoad() {
    self.view.backgroundColor = .white;
    
    let floatingView = UIView();
    self.floatingView = floatingView;
    
    floatingView.backgroundColor = UIColor(
      hue: 0/360,
      saturation: 50/100,
      brightness: 100/100,
      alpha: 1.0
    );
  
    self.view.addSubview(floatingView);
  };
  
  override func viewDidLayoutSubviews() {
    guard let floatingView = self.floatingView,
          let layoutContext = self.layoutContext
    else { return };
    
    let computedRect =
      layoutConfig.computeRect(usingLayoutValueContext: layoutContext);
    
    floatingView.frame = computedRect;
  };
};



文档

TBA



示例

TBA



其他与联系方式