StoryboardConstraint
使用 Storyboard 中创建的自动布局约束的一种简单方法。
特性
- 预定义的基本约束:顶部、底部、左边缘、右边缘、高度、宽度、中心 X、中心 Y
- 通过视图查找特定约束的完整方法
Podfile
要使用 CocoaPods 将 StoryboardConstraint 集成到您的 Xcode 项目中,请在 Podfile
中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
target 'TargetName' do
use_frameworks!
pod 'StoryboardConstraint'
end
然后,运行以下命令:
$ pod install
如何使用
1. 在您的项目中添加UIView+StoryboardConstraint.swift
2. 获取约束条件
您可以通过以下方式在Storyboard中获取约束集
customView.heightConstraint?.constant = 200
customView.topConstraint?.constant = 20
您还可以设置自定义约束标识符然后这样获取它
view.constraint(withIdentifier: "customWidth", searchInSubviews: true)?.constant = 50
如果您想要,这样就可以使用指定的属性获取所有约束
view.constraints(withAttribute: .height)
此方法按优先级顺序返回找到的所有约束。
要求
当前版本与以下兼容
- Swift 5.0
- iOS 10或更高版本