ABStackKit 0.1.0

ABStackKit 0.1.0

AshishBhandari 维护。



  • 作者
  • Ashish Bhandari

ABStackKit

使用 Swift 4 编写,展示一个多彩的可滚动 StackView。通过 StackViewEmbeddable 协议或 StackViewController 的子类来简单地管理 StackView 的生命周期。另外,如果您需要为其添加颜色背景、应用旋转或在其视图的一部分中使用,这是您需要的唯一库。仅支持 Swift。

使用 CocoaPods 进行安装

CocoaPods 是 Swift 和 Objective-C 的依赖管理器。ABStackKit 可以通过 CocoaPods 安装。您可以使用以下命令来安装它

$ gem install cocoapods

Podfile

要安装它,只需将以下行添加到 Podfile 中

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'

target 'TargetName' do
    pod "ABStackKit"
end

然后,运行以下命令

$ pod install

使用

示例代码(Swift)

import ABStackKit

// setup the stack view
let stackView = StackView(frame: view.frame)
stackView.delegate = self

// embedd to your controller's view
view.addSubview(stackView)
view.addEdgeAnchors(onView: stackView)

// implement methods from StackViewEmbeddable protocol
func willConfigure(_ stackView: StackView) {
    stackView.axis = .vertical
    stackView.alignment = .center
    stackView.distribution = .equalSpacing
    stackView.spacing = 9
    stackView.animDuration = 0.99
    stackView.clockRadian = .pi/99
    stackView.backgroundColor = .red
    stackView.layoutMargins = UIEdgeInsets(top: 9, left: 9, bottom: 9, right: 9)
}
    
func numberOfChildViews() -> Int {
    return 6
}
    
func childViewForIndex(_ index: Int) -> UIView {
    let childView = UIView(frame: CGRect(x: 0, y: 0, width: view.bounds.width/2, height: view.bounds.height/2))
    childView.backgroundColor = .blue
    
    let lblNumber = UILabel()
    lblNumber.text = "View \(index+1)"
    lblNumber.textColor = .white
    childView.addSubview(lblNumber)
    childView.addCenterXYAnchors(onView: lblNumber)
    
    return childView
}

func didSelectChildView(_ view: UIView, index: Int) {
    if let height = view.constraint(withIdentifier: ConstraintTag.H)?.constant {
	    view.constraint(withIdentifier: ConstraintTag.H)?.constant = height/2
	    UIView.animate(withDuration: 0.25) {
	        view.superview?.layoutIfNeeded()
	    }
    }
}

func didScrollToChildView(_ view: UIView, index: Int) {}

// ...

通信

如果你看到改进项目的办法

  • 如果你 发现了bug并能提供可靠地重现它的步骤,请打开问题
  • 如果你 有功能请求,请打开问题
  • 如果你 想贡献,请提交pull请求

推荐遵循GitHub Swift 编程风格指南

谢谢!✌️

待办

  • 添加 Swift 包管理器支持

作者

Ashish Bhandari,[email protected]

许可

ABStackKit可在MIT许可下使用。有关更多信息,请参阅LICENSE文件。