CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

SizeSlideButton 1.5

SizeSlideButton 1.5

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Mar 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Jonathan Cardasis.



  • By
  • Jonathan Cardasis

SizeSlideButton

A fun Swift UIControl for picking a size. Demo Animation

Installation

Manually

Add the SizeSlideButton.swift class to your project.

Examples

let condensedFrame = CGRect(x: 280, y: 70, width: 32, height: 32) //Width and Height should be equal
let fancyControl = SizeSlideButton(condensedFrame: condensedFrame)

fancyControl.trackColor = UIColor(red: 38/255, green: 50/255, blue: 56/255, alpha: 1)
fancyControl.handle.color = UIColor.white
fancyControl.addTarget(self, action: #selector(newSizeSelected), for: .touchDragFinished)
fancyControl.addTarget(self, action: #selector(sizeSliderTapped), for: .touchUpInside)
self.view.addSubview(fancyControl)


func newSizeSelected(_ sender: SizeSlideButton){
    //Do something once a size is selected and the control let go
    // You can now use the senders .value for a value between 0 and 1
    // Or use the handle's height (handle.height) as a multiplier for size
    print("Value: \(sender.value)")
    print("Size multiplier: \(sender.handle.height)")

    // Ex: self.paintbrush.brushSize = kDefaultBrushSize * sender.handle.height
}

func sizeSliderTapped(_ sender: SizeSlideButton){
    //Do something when the button is tapped
    print("Tip Tap")
 }

Output:

Documentation

  • init(condensedFrame: CGRect) will set the frame of where the condensed frame should lie (width and height should be equal)
  • init(frame: CGRect) will set the frame of where the frame should lie when fully expanded
  • currentSize to obtain the size the person has selected
  • handlePadding sets the padding around the handle (default is the left side’s radius). Works best as <= leftSideRadius
  • handle.color is the slider’s handle color
  • handle.height/handle.width gets the sizes of the handle and can be best used as a multiplier against a constant default size
  • trackColor is the color of the track
  • value is a value between 0 and 1.0 of where the handle was positioned relative on the track
  • leftSideRadius and rightSideRadius return the radii of the left and right sides of the frame when expanded
  • currentState returns if the control is condensed or expanded
  • animationType specifies the animation type used when letting go of the control

Supported UIControlEvents

  • touchUpInside is called when a tap on the control is released
  • valueChanged is called when the slider is moved
  • touchDown is called both when a long press is detected or a regular touch is detected
  • touchDragFinished (A custom UIControlEvent) is called when the slider has selected a new value and been released

License

SizeSlideButton is available under the MIT license. See the LICENSE file for more info.