A config-based layout calculator.
ComputableLayout
is available through CocoaPods. To install it, simply add the following line to your Podfile
:
pod 'ComputableLayout'
Method: #1: Via Xcode GUI:
- File > Swift Packages > Add Package Dependency
- Add
https://github.com/dominicstop/ComputableLayout.git
Method: #2: Via Package.swift
:
- Open your project's
Package.swift
file. - Update
dependencies
inPackage.swift
, and add the following:
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
- 🐤 Twitter/X:
@GoDominic
- 💌 Email:
[email protected]
- 🌐 Website dominicgo.dev