APStepControlView 1.0.0

APStepControlView 1.0.0

ponomarevsoloud维护。



  • Alex Ponomarev

APStepControlView

Version License Platform Swift

APStepControlView是美丽的控制元素,为用户提供了一种简单而可爱的方式来减少列表中的元素数量。它可以用于操作Navigation控制器的层次结构。

要求

  • iOS 10.0+
  • Xcode 9

安装

您可以使用CocoaPods通过将其添加到您的Podfile中来安装APStepControlView

platform :ios, '10.0'
use_frameworks!

target 'MyApp' do
    pod 'APStepControlView'
end

使用

初始化

import APStepControlView

APStepControlView有一个初始化器用来设置步骤的初始数量。

let stepControlView = APStepControlView(sectionsCount: 5)

此外,APStepControlView是一个UIView,可以像它一样初始化。

let rect = CGRect(x: 40, y: 200, width: 200, height: 40)
let stepControlView = APStepControlView(frame: rect)

APStepControlViewDelegate

您可以通过实现APStepControlViewDelegate来接收有关APStepControlView操作的通知并控制行为

class StepControlViewDelegateImpl: APStepControlViewDelegate {
  func stepControlView(_ stepControlView: APStepControlView, didChangeStepsCountFrom count: Int, to newCount: Int) {
    print("Number of steps changed from \(count) to \(newCount)")
  }
  
  func stepControlView(_ stepControlView: APStepControlView, shouldPopStepWithIndex index: Int) -> Bool {
    return index > 0 // In an array, at least one element
  }
}
let stepControlViewDelegateImpl = StepControlViewDelegateImpl()

stepControlView.delegate = stepControlViewDelegateImpl

定制

步骤指示器颜色可以自定义。可以为每种指示器类型使用ColorStyles对象进行设置。

Illustration

stepControl.commonIndicatorColorStyle.circle = .black
stepControl.peekIndicatorColorStyle.circle = .red
stepControl.peekIndicatorColorStyle.border = .blue

如果您不需要获取用户触摸控制,并希望使用强制pow()pop()来操作,只需设置isUserInteractionEnabled = false

自动布局

您可以通过framecenter和其他属性定位和调整视图大小,或者使用约束。如果您使用约束,则不应强制设置宽度。它允许在推入和弹出步骤时自动调整视图大小,并在点击时正确地增加视图大小。