ComputableLayout
基于配置的布局计算器。
安装
Cocoapods
ComputableLayout
通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
:
pod 'ComputableLayout'
Swift Package Manager (SPM)
方法:#1:通过 Xcode GUI
- 文件 > Swift Packages > 添加包依赖
- 添加
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
其他与联系方式
- 🐤 Twitter/X:
@GoDominic
- 💌 邮箱:
[email protected]
- 🌐 网站 dominicgo.dev