Skip to content

ponysoloud/ap-step-control-view

Repository files navigation

APStepControlView

Version License Platform Swift

APStepControlView is beautiful control element that provides to user easy and lovely way to decrease count of elements in list. It may be useful to manipulate with Navigation controller hierarchy.

Illustration

Requirements

  • iOS 10.0+
  • Xcode 9

Installation

You can use CocoaPods to install APStepControlView by adding it to your Podfile:

platform :ios, '10.0'
use_frameworks!

target 'MyApp' do
    pod 'APStepControlView'
end

Usage

Initialization

import APStepControlView

APStepControlView have one initializer to set initial count of steps.

let stepControlView = APStepControlView(stepsCount: 5)

Also, APStepControlView is a UIView and can be initialized like it.

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

APStepControlViewDelegate

You can implement APStepControlViewDelegate to be notified about actions with APStepControlView and control behaviour

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

Customizing

Steps indicators colors are customizable. It can be set with ColorStyles objects for every Indicator type.

Illustration

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

If you don't need to take user touch control and want to manipulate it with forced pow() and pop(), just set isUserInteractionEnabled = false.

AutoLayout

You can position and resize view through frame, center and other properties or use constraints. If you use constraints, you shouldn't strongly fix width. It allows to autoresize view on pushing and poping steps, increase size of view correctly on tap.