[快速学会Swift第三方库] Cartography篇
Cartography 是用来声明 Swift 中的 Auto Layout,无需输入任何 stringly 就可设置自己 Auto Layout 的约束声明。
目录
编码之前
导入 Cartography
推荐使用CocoaPods进行导入,CocoaPods是一个负责管理iOS项目中第三方开源库的工具,安装CocoaPods之后使用命令行就能轻松地对所有第三方开源库进行安装和更新,而不需要每次上GitHub去下载。
CocoaPods的安装过程传送门:iOS 9 导入类库全面详尽过程(Ruby安装->CocoaPods安装->导入类库)
手动下载:GitHub-Cartography主页
装好CocoaPods后,修改Podfile文件内容为如下:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
target 'Web' do
pod 'Cartography', '~> 0.6.0'
end
xcodeproj 'Desktop/Web/Web.xcodeproj'
target后面为工程名,最后一行为工程路径(这里的Web是我的工程名)
再执行命令:
$ pod install
其他操作
另外还需要在Target->工程名->Build Settings->Search Paths->User Header Search Paths处添加Cartography所在的目录:
最后在你需要用到Cartography的类中加上:
import Cartography
基本约束
示例代码
func baseConstrain() {
let view1 = UIView()
let view2 = UIView()
view1.backgroundColor = UIColor.blu