# SnowLayout **Repository Path**: jbxb/snow-layout ## Basic Information - **Project Name**: SnowLayout - **Description**: 根据自动布局封装的快速布局工具,包含“线性布局”、“网格布局”、“弹性布局” - **Primary Language**: Swift - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2023-03-11 - **Last Updated**: 2024-03-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SnowLayout #### 介绍 根据自动布局封装的快速布局工具,包含“线性布局”、“网格布局”、“弹性布局” #### 安装教程 Cocoapods ``` pod 'SnowLayout', :git => 'https://gitee.com/jbxb/snow-layout.git' ``` #### 使用说明 1. 网格布局 ```swift let gridView = SNGridView(alignment: .fill, horizontalSpacing: 2, verticalSpacing: 2) { for row in 0..<10 { SNGridItem(distribution: .fillEqually) { for column in 0..<2 { UILabel(text: "行:\(row),列:\(column)") .textColor(.white) .backgroundColor(.red) } } } } .backgroundColor(.green) gridView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(gridView) NSLayoutConstraint.activate([ gridView.centerXAnchor.constraint(equalTo: view.centerXAnchor), gridView.centerYAnchor.constraint(equalTo: view.centerYAnchor) ]) ``` 2. 线性布局 `UIStackView`的封装 * 垂直方向 ```swift let vView = SNVStackView { for row in 0..<20 { UILabel(text: "行:\(row)") } } .backgroundColor(.green) vView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(vView) NSLayoutConstraint.activate([ vView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), vView.centerXAnchor.constraint(equalTo: view.centerXAnchor) ]) ``` * 水平方向 ```swift let hView = SNHStackView { for column in 0..<5 { UILabel(text: "列:\(column)") } } .backgroundColor(.green) hView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(hView) NSLayoutConstraint.activate([ hView.topAnchor.constraint(equalTo: vView.bottomAnchor, constant: 10), hView.centerXAnchor.constraint(equalTo: view.centerXAnchor) ]) ``` 3. 弹性布局 ```swift let flexView = SNHFlexView(lineSpacing: 5, interitemSpacing: 5) { for _ in 0..