Skip to content

Commit

Permalink
Fixed readme, fixed podspec
Browse files Browse the repository at this point in the history
  • Loading branch information
MaherKSantina committed Jun 10, 2019
1 parent 9b4daad commit 97908df
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 11 deletions.
27 changes: 27 additions & 0 deletions Example/MSSnappingSlider/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,44 @@
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="4" translatesAutoresizingMaskIntoConstraints="NO" id="inF-p3-ckS" customClass="MSSnappingSlider" customModule="MSSnappingSlider">
<rect key="frame" x="14" y="88" width="347" height="31"/>
</slider>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="T9j-ZA-FDr">
<rect key="frame" x="16" y="142" width="343" height="77.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Step: 1" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TWf-08-9r8">
<rect key="frame" x="0.0" y="0.0" width="343" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Threshold: 0.5" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Pvj-rI-a6n">
<rect key="frame" x="0.0" y="28.5" width="343" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Snap Value" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Qov-br-5vT">
<rect key="frame" x="0.0" y="57" width="343" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="inF-p3-ckS" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="16" id="5ee-R6-mBf"/>
<constraint firstItem="T9j-ZA-FDr" firstAttribute="top" secondItem="inF-p3-ckS" secondAttribute="bottom" constant="24" id="TH1-E7-L3K"/>
<constraint firstAttribute="trailing" secondItem="T9j-ZA-FDr" secondAttribute="trailing" constant="16" id="p2C-oY-iWk"/>
<constraint firstItem="inF-p3-ckS" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="24" id="rgX-8i-C3E"/>
<constraint firstItem="T9j-ZA-FDr" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="16" id="uFP-s8-AUN"/>
<constraint firstAttribute="trailing" secondItem="inF-p3-ckS" secondAttribute="trailing" constant="16" id="xaN-vu-tQu"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="Snapping Slider" id="Gj6-50-foy"/>
<connections>
<outlet property="mySlider" destination="inF-p3-ckS" id="LKi-7S-BgA"/>
<outlet property="valueLabel" destination="Qov-br-5vT" id="GEY-jP-yaj"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
Expand Down
3 changes: 2 additions & 1 deletion Example/MSSnappingSlider/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import MSSnappingSlider
class ViewController: UIViewController {

@IBOutlet weak var mySlider: MSSnappingSlider!
@IBOutlet weak var valueLabel: UILabel!

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -27,7 +28,7 @@ class ViewController: UIViewController {

extension ViewController: MSSnappingSliderDelegate {
func snappingSlider(_ snappingSlider: MSSnappingSlider, didChangeValueTo newValue: Float) {
print(newValue)
valueLabel.text = "\(newValue)"
}
}

2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
MSSnappingSlider: 015dcaa712dcd893cbe8eadd0ddc9d23deb10606
MSSnappingSlider: 0ad29efa0522ce43f8119fa29a084c51f76172f1

PODFILE CHECKSUM: 6093b1b896405af454bb63c4a96b797ab6813e4f

Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/MSSnappingSlider.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions MSSnappingSlider.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Pod::Spec.new do |s|
s.name = 'MSSnappingSlider'
s.version = '0.1.0'
s.summary = 'A short description of MSSnappingSlider.'
s.summary = 'Subclass of UISlider which snaps to specific values based on the step value provided.'

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
Expand All @@ -18,7 +18,7 @@ Pod::Spec.new do |s|
# * Finally, don't worry about the indent, CocoaPods strips it!

s.description = <<-DESC
TODO: Add long description of the pod here.
MSSnappingSlider is a subclass of `UISlider` that will give you access to 2 attributes, `step` and `threshold` where you can define exactly how the snapping should work.
DESC

s.homepage = 'https://github.com/MaherKSantina/MSSnappingSlider'
Expand Down
11 changes: 11 additions & 0 deletions MSSnappingSlider/Classes/MSSnappingSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@

import UIKit

/**
Handles all events emitted from the snapping slider
*/
public protocol MSSnappingSliderDelegate: AnyObject {

/**
Will be called whenever the slider snaps to a value, or the user lifts their hand from the slider. Note: This delegate function will sometimes be called multiple times for the same value. This happens when users drag to a new value and lift their finger up.
- parameter snappingSlider: The slider that its value changed
- parameter newValue: The new snapped value that the slider reached
*/
func snappingSlider(_ snappingSlider: MSSnappingSlider, didChangeValueTo newValue: Float)
}

public extension MSSnappingSliderDelegate {

// Default implementation for the change value event
func snappingSlider(_ snappingSlider: MSSnappingSlider, didChangeValueTo newValue: Float) {}
}

Expand Down
34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@
# MSSnappingSlider

[![CI Status](https://img.shields.io/travis/MaherKSantina/MSSnappingSlider.svg?style=flat)](https://travis-ci.org/MaherKSantina/MSSnappingSlider)
[![Version](https://img.shields.io/cocoapods/v/MSSnappingSlider.svg?style=flat)](https://cocoapods.org/pods/MSSnappingSlider)
[![License](https://img.shields.io/cocoapods/l/MSSnappingSlider.svg?style=flat)](https://cocoapods.org/pods/MSSnappingSlider)
[![Platform](https://img.shields.io/cocoapods/p/MSSnappingSlider.svg?style=flat)](https://cocoapods.org/pods/MSSnappingSlider)
MSSnappingSlider is a subclass of `UISlider` that will give you access to 2 attributes, `step` and `threshold` where you can define exactly how the snapping should work.

![Snapping Slider](https://user-images.githubusercontent.com/24646608/59196589-6d05cb00-8bd2-11e9-99f9-8e398f08c7ce.gif)

## Specifications
### `step`
`step` defines the value of the displacement.
For example, if the `step` is `1`, the slider will only snap to integer value (1.0, 2.0, -1.0 ...)

### `threshold`
`threshold` is the maximum magnitude that the value can reach before snapping to the adjacent value.
For example, if the `step` is `1` and the `threshold` is `0.5`, as soon as the slider value passes `0.5`, it will snap to `1`

### `MSSnappingSliderDelegate`
Handles all events emitted from the snapping slider. It has only one function:

```swift
func snappingSlider(_ snappingSlider: MSSnappingSlider, didChangeValueTo newValue: Float)
```

This function will be called whenever the slider snaps to a value, or the user lifts their hand from the slider. Note: This delegate function will sometimes be called multiple times for the same value. This happens when users drag to a new value and lift their finger up.

## Example

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

## Requirements

XCode 10.2

## Installation

### Cocoapods
MSSnappingSlider is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:

```ruby
pod 'MSSnappingSlider'
```

### Carthage

```ruby
github "MSSnappingSlider"
```

## Author

MaherKSantina, maher.santina90@gmail.com
Expand Down

0 comments on commit 97908df

Please sign in to comment.