Skip to content

dominicstop/ComputableLayout

Repository files navigation

ComputableLayout

A config-based layout calculator.

ComputaleLayoutTestPresets



Installation

Cocoapods

ComputableLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ComputableLayout'

Swift Package Manager (SPM)

Method: #1: Via Xcode GUI:

  1. File > Swift Packages > Add Package Dependency
  2. Add https://github.com/dominicstop/ComputableLayout.git

Method: #2: Via Package.swift:

  • Open your project's Package.swift file.
  • Update dependencies in Package.swift, and add the following:
dependencies: [
  .package(url: "https://github.com/dominicstop/ComputableLayout.git",
  .upToNextMajor(from: "0.1.0"))
]



Basic Usage

🔗 Full Example

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;
  };
};



Documentation

TBA



Examples

TBA



Misc and Contact

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published