6 Commits

Author SHA1 Message Date
Jalal Ouraigua c234281a9e Progress 2018-12-15 21:37:05 +00:00
Jalal Ouraigua 070d2615c3 Work in progress 2018-12-14 00:40:52 +00:00
Jalal Ouraigua 4206b108a9 Work in progress 2018-12-12 00:10:48 +00:00
Jalal Ouraigua 9596434dca Update functionality 2018-12-11 16:28:38 +00:00
Jalal Ouraigua 539be74ce8 Add UIControl edit notification 2018-12-11 06:21:40 +00:00
Jalal Ouraigua 70fa6d1acd Add value change Target-Action 2018-12-10 05:23:52 +00:00
9 changed files with 64 additions and 17 deletions
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="T5Y-X3-uD8">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="T5Y-X3-uD8">
<device id="retina6_1" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
@@ -39,13 +39,13 @@
<color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="color2">
<color key="value" red="0.15235996039999999" green="0.17974209029999999" blue="0.22156283139999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="value" red="0.15294117647058825" green="0.1803921568627451" blue="0.2196078431372549" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="color1">
<color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="color4">
<color key="value" red="0.13288810049999999" green="0.14611955109999999" blue="0.1740877602" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="value" red="0.13333333333333333" green="0.14509803921568626" blue="0.17254901960784313" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="maxidotOffColor">
<color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
@@ -57,7 +57,7 @@
<color key="value" red="1" green="0.5" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="highlightColor">
<color key="value" red="0.33810979099999999" green="0.36411823659999998" blue="0.42480460930000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="value" red="0.33725490196078434" green="0.36470588235294116" blue="0.42352941176470588" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="textColor">
<color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
@@ -70,7 +70,7 @@
<real key="value" value="0.80000000000000004"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="pointerColor2">
<color key="value" red="0.2530443235" green="0.27250927159999999" blue="0.31792748339999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="value" red="0.25490196078431371" green="0.27058823529411763" blue="0.31764705882352939" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="pointerColor1">
<color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
@@ -197,7 +197,7 @@
<viewLayoutGuide key="safeArea" id="zts-4c-D2G"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="color1">
<color key="value" red="0.10980392160000001" green="0.12941176469999999" blue="0.15686274510000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="value" red="0.10980392156862745" green="0.12941176470588234" blue="0.15686274509803921" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="color2">
<color key="value" red="0.1333333333" green="0.14117647059999999" blue="0.1647058824" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+1 -1
View File
@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.5</string>
<string>1.0.6</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
+21 -1
View File
@@ -11,7 +11,14 @@ import JOCircularSlider
class ViewController: UIViewController {
@IBOutlet weak var circularSlider: CircularSlider!
@IBOutlet weak var circularSlider: CircularSlider! {
didSet {
circularSlider.addTarget(self, action: #selector(handleValueChanged(_:)), for: .valueChanged)
circularSlider.addTarget(self, action: #selector(didBeginEditing), for: .editingDidBegin)
circularSlider.addTarget(self, action: #selector(didEndEditing), for: .editingDidEnd)
}
}
@IBOutlet weak var stackView: UIStackView!
@IBOutlet weak var widthConstraint: NSLayoutConstraint! {
didSet {
@@ -117,6 +124,19 @@ class ViewController: UIViewController {
circularSlider.maxidotOnColor = UIColor(hue: CGFloat(sender.value), saturation: 1, brightness: 1, alpha: 1)
}
@objc func didBeginEditing() {
print("\n" + "didBeginEditing\n")
}
@objc func didEndEditing() {
print("\n" + "didBeginEditing\n")
}
@IBAction func handleValueChanged(_ sender: CircularSlider) {
print("value: \(sender.value)")
}
}
@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.5</string>
<string>1.0.6</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.5</string>
<string>1.0.6</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.5</string>
<string>1.0.6</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
+1 -1
View File
@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = 'JOCircularSlider'
s.version = '1.0.5'
s.version = '1.0.6'
s.summary = 'A highly customisable and reusable iOS circular slider.'
# This description is used to generate tags and improve search results.
+25 -1
View File
@@ -258,6 +258,11 @@ open class CircularSlider: UIControl {
set { renderer.isClockwise = newValue }
}
@IBInspectable open var isNegative: Bool {
get { return renderer.isNegative }
set { renderer.isNegative = newValue }
}
// MARK: - Private Properties
lazy private var renderer = Renderer(with: self)
@@ -291,6 +296,7 @@ open class CircularSlider: UIControl {
let distanceToOrigin = location - centerPoint
lastTouchAngle = atan2(distanceToOrigin.y, distanceToOrigin.x).toDegree
sendActions(for: .editingDidBegin)
}
override open func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
@@ -309,6 +315,13 @@ open class CircularSlider: UIControl {
guard abs(angelDeltaAsPercentage) < 1 else { return }
let newValue = isClockwise ? value + angelDeltaAsPercentage : value - angelDeltaAsPercentage
setValue(newValue, isPercentage: true)
//sendActions(for: .valueChanged)
}
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
sendActions(for: .editingDidEnd)
}
// MARK: - Public
@@ -330,6 +343,8 @@ open class CircularSlider: UIControl {
renderer.updateText(with: value)
renderer.updatePointerView(in: bounds, value: value)
renderer.maxiDotView.updateColors(using: value)
sendActions(for: .valueChanged)
}
open func setTextFont(named: String, textColor: UIColor, multiplier: CGFloat) {
@@ -361,6 +376,11 @@ class Renderer {
maxiDotView.isClockwise = isClockwise
}
}
fileprivate var isNegative: Bool = false {
didSet {
}
}
fileprivate var textFieldIsHidden: Bool = false
fileprivate var fontSizeMultiplier: CGFloat = 0.5
@@ -478,7 +498,8 @@ private extension Renderer {
return
}
circularSlider.setValue(Float(newValue))
maxiDotView.layoutSubviews()
circularSlider.sendActions(for: .editingDidEnd)
//maxiDotView.setNeedsLayout()
}
// MARK: - Updates
@@ -514,6 +535,9 @@ private extension Renderer {
// convert value (0...1) to a value within proposed range
value = Int(newValue * (maximumValue - minimumValue) + minimumValue)
}
if isNegative {
value = Int(Float(value) - maximumValue)
}
switch value {
case Int(minimumValue): textField.text = "MIN"
case Int(maximumValue): textField.text = "MAX"
+6 -3
View File
@@ -38,9 +38,6 @@ pod 'JOCircularSlider'
## Usage
1. Visually:
```swift
import JOCircularSlider
```
Drag a UIView to your storyboard, change its class of to CircularSlider and start visually customising the design to your liking.
All the parameters are IBInspectable, so you can configure the slider straight from the attribute inspector tab, without having to write a single line of code.
@@ -68,6 +65,7 @@ The slider's `value` property is read-only.
*/
open private (set) var value: Float = 0
```
To set the slider's value use the following:
```swift
/**
@@ -78,6 +76,11 @@ To set the slider's value use the following:
open func setValue(_ newValue: Float, isPercentage: Bool = false)
```
In order to get value change notifications, use the `Target-Action` pattern which is an inherent part of UIControl, like so:
``` swift
circularSlider.addTarget(target: Any?, action: Selector, for: UIControl.valueChanged)
```
To Control the text's appearance, use these:
```swift
open func setTextFont(named: String, textColor: UIColor, multiplier: CGFloat)