Latest 1.0.0
Homepage https://github.com/ccabanero/MidpointSlider
License MIT
Platforms ios 8.3, requires ARC
Frameworks UIKit, QuartzCore
Authors

Version
License
Platform
Swift 2.0

MidpointSlider is a custom iOS control that allows the user to pull left or right from the slider’s center when choosing a value.

screenshot

Requirements

  • Xcode 7.x
  • Swift 2.x
  • iOS Deployment Target (earliest supported version) is 8.3

Installation

Cocoa Pods

MidpointSlider is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "MidpointSlider"

For example, the Podfile in your project directory should resemble the following:

platform :ios, '8.3'
use_frameworks!

target 'YourProjectName' do
    pod 'MidpointSlider'
end

Manual Installation

Alternatively, you can manually copy the following files directly into your Xcode project:

screenshot

Usage (Programmatically)

To run the example project, clone the repo, and run pod install from the Example directory first.

Alternatively, see the code sample below:

// STEP 1: Import the MidpointSlider.
import MidpointSlider

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // STEP 2: Instantiate a new MidPointSlider.
        let midpointSlider = MidpointSlider(frame: CGRect(x: 40, y: 300, width: 300, height: 30))

        // STEP 3: Set the minimum and maximum values for the slider and the starting value.
        midpointSlider.minimumValue = -100
        midpointSlider.maximumValue = 100
        midpointSlider.currentValue = 70

        // Optional: Set the color of the MidpointSlider to match the look and feel of your app.
        midpointSlider.trackTintColor = UIColor.orangeColor()

        // STEP 4: Add a target and action to handle when user changes the slider value.
        midpointSlider.addTarget(self, action: "midpointSliderValueChanged:", forControlEvents: UIControlEvents.ValueChanged)

        // STEP 5: Add the MidpointSlider to your view.
        view.addSubview(midpointSlider)
    }

    // STEP 6: Declare your action method to handle when the slider value changes.
    func midpointSliderValueChanged(midpointSlider: MidpointSlider) {

        let sliderValue = midpointSlider.currentValue

        print("Value changed to : (sliderValue))")
    }
}

Usage (with Storyboards)

MidpointSlider can also be added to your project using Storyboards by performing the following steps:

Step 1. In Xcode, drag a UIView to your target scene in your Storyboard. In the Size Inspector, change the height of the view to 30. Change the width and position to any values that you’d like. See screenshot below.

screenshot

Step 2. In the Identity Inspector, declare the class as MidpointSlider and press enter. You will see the MidpointSlider control appear. See screenshot below.

screenshot

Step 3. In the Attributes Inspector, change the minimum slider value, maximum slider value, current value, and tint color of the MidpointSlider to values that make sense for your application. See screenshot below.

screenshot

Step 4. ‘Control Button Drag’ from the MidpointSlider on your scene to your associated ViewController class. Choose the following options to create an action method:

  • Connection = Action
  • Name = handleValueChanged (or any other meaningful action method name)
  • Type = MidpointSlider

Click on the Connect button. See screenshot below.

screenshot

Step 5. Add an Import statement for the library and Implement your action method.

For example:

import MidpointSlider

...

@IBAction func handleValueChanged(sender: MidpointSlider)  {

    let sliderValue = midpointSlider.currentValue

    print("Value changed to : (sliderValue))")
}

Author

Clint Cabanero

License

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

Latest podspec

{
    "name": "MidpointSlider",
    "version": "1.0.0",
    "summary": "MidpointSlider is a custom iOS control that allows the user to pull left or right from the slider's center when choosing a value.",
    "description": "MidpointSlider is a custom iOS control that allows the user to pull left or right from the slider's center when choosing a value.  The slider's minimum and maximum values are configurable as well as the slider tint color.",
    "homepage": "https://github.com/ccabanero/MidpointSlider",
    "screenshots": "http://s3.amazonaws.com/big-leaf-public/pod_screenshots/MidpointSlider.gif",
    "license": "MIT",
    "authors": {
        "Clint Cabanero": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ccabanero/MidpointSlider.git",
        "tag": "1.0.0"
    },
    "social_media_url": "https://twitter.com/clintcabanero",
    "platforms": {
        "ios": "8.3"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "MidpointSlider": [
            "Pod/Assets/*.png"
        ]
    },
    "frameworks": [
        "UIKit",
        "QuartzCore"
    ]
}

Pin It on Pinterest

Share This