StackScrollView 1.6.3

StackScrollView 1.6.3

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2022年1月
SPM支持 SPM

muukiimuukii 维护。



StackScrollView

CI Status Version License Platform Carthage compatible

⚠️本示例使用 demo-components。StackScrollView 没有默认组件。StackScrollView 类似于 UIStackView。因此,我们需要创建所需的组件。

这是什么?

StackScrollView 可以轻松构建 UI。

StackScrollView 包含 UICollectionView。UICollectionView 通过 AutoLayout 计算视图的大小,然后显示出来(使用 systemLayoutSizeFitting)。

  • 我们在 StackScrollView 上使用 StackCell 而不是 Cell
  • 我们不再需要考虑 Cells 的复用。
  • StackCell 需要基于约束的布局。

用法

基本用法

let stack = StackScrollView()

stack.append(view: ...)

stack.remove(view: ..., animated: true)

APIs

StackScrollView

func append(view: UIView)
func remove(view: UIView, animated: Bool)
func scroll(to view: UIView, at position: UICollectionViewScrollPosition, animated: Bool)

StackCellType

StackScrollView 不需要 StackCellType。如果 StackCellStackCellType,则可以轻松控制 StackCell。

func scrollToSelf(animated: Bool)
func scrollToSelf(at position: UICollectionViewScrollPosition, animated: Bool)
func updateLayout(animated: Bool)
func remove()

示例代码包含了这些 API 的使用方法。

从代码创建 CustomCell

我们必须完全设置约束。

final class LabelStackCell: UIView {
  
  private let label = UILabel()
  
  init(title: String) {
    super.init(frame: .zero)
    
    addSubview(label)
    label.translatesAutoresizingMaskIntoConstraints = false
    
    label.topAnchor.constraint(greaterThanOrEqualTo: topAnchor, constant: 8).isActive = true
    label.bottomAnchor.constraint(lessThanOrEqualTo: bottomAnchor, constant: 8).isActive = true
    label.rightAnchor.constraint(equalTo: rightAnchor, constant: 8).isActive = true
    label.leftAnchor.constraint(equalTo: leftAnchor, constant: 8).isActive = true
    label.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
    heightAnchor.constraint(greaterThanOrEqualToConstant: 40).isActive = true
    
    label.font = UIFont.preferredFont(forTextStyle: .body)
    label.text = title
  }
}
let stack = StackScrollView()
stack.append(view: LabelStackCell(title: "Label"))

从 XIB 创建 CustomCell

我们可以使用 XIB 中的 UIView。

此框架包含 NibLoader<T: UIView>。这可能对您有帮助。

创建所有内容

您可以从Cell中创建任何内容。请检查StackScrollView-Demo

手动布局

您可以创建具有手动布局的Cell。

如果使用手动布局,Cell需要使用ManualLayoutStackCellType。然后,根据size(maxWidth:maxHeight)返回的最大尺寸进行自适应。

作者

muukii, [email protected]

许可证

StackScrollView遵守MIT许可证。有关更多信息,请参阅LICENSE文件。