Skip to content

Commit 7c75b9b

Browse files
author
Xavier Schott
committed
Fixes #26
1 parent 8d016e6 commit 7c75b9b

10 files changed

Lines changed: 81 additions & 37 deletions

File tree

TGPControls/TGPDiscreteSlider.swift

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ public class TGPDiscreteSlider:TGPSlider_INTERFACE_BUILDER {
4141
}
4242
}
4343

44-
@IBInspectable public var tickTintColor:UIColor? = nil {
44+
@IBInspectable public var minimumTickTintColor:UIColor? = nil {
45+
didSet {
46+
layoutTrack()
47+
}
48+
}
49+
50+
@IBInspectable public var maximumTickTintColor:UIColor? = nil {
4551
didSet {
4652
layoutTrack()
4753
}
@@ -78,7 +84,7 @@ public class TGPDiscreteSlider:TGPSlider_INTERFACE_BUILDER {
7884
}
7985
}
8086

81-
@IBInspectable public var maximumTrackTintColor:UIColor = UIColor(white: 0.71, alpha: 1) {
87+
@IBInspectable public var maximumTrackTintColor = UIColor(white: 0.71, alpha: 1) {
8288
didSet {
8389
layoutTrack()
8490
}
@@ -223,12 +229,19 @@ public class TGPDiscreteSlider:TGPSlider_INTERFACE_BUILDER {
223229
var ticksAbscissae:[CGPoint] = []
224230
var thumbAbscissa:CGFloat = 0
225231
var thumbLayer = CALayer()
232+
233+
var trackLayer = CALayer()
226234
var leftTrackLayer = CALayer()
227235
var rightTrackLayer = CALayer()
228-
var trackLayer = CALayer()
229236
var leadingTrackLayer: CALayer!
230237
var trailingTrackLayer: CALayer!
238+
231239
var ticksLayer = CALayer()
240+
var leftTicksLayer = CALayer()
241+
var rightTicksLayer = CALayer()
242+
var leadingTicksLayer: CALayer!
243+
var trailingTicksLayer: CALayer!
244+
232245
var trackRectangle = CGRect.zero
233246
var touchedInside = false
234247
var localeCharacterDirection = CFLocaleLanguageDirection.leftToRight
@@ -275,21 +288,27 @@ public class TGPDiscreteSlider:TGPSlider_INTERFACE_BUILDER {
275288
trailingTrackLayer = (.rightToLeft == localeCharacterDirection)
276289
? leftTrackLayer
277290
: rightTrackLayer
278-
279-
// Track is a clear clipping layer, and left + right sublayers, which brings in free animation
291+
leadingTicksLayer = (.rightToLeft == localeCharacterDirection)
292+
? rightTicksLayer
293+
: leftTicksLayer
294+
trailingTicksLayer = (.rightToLeft == localeCharacterDirection)
295+
? leftTicksLayer
296+
: rightTicksLayer
297+
298+
// Track and ticks are in a clear clipping layer, and left + right sublayers,
299+
// which brings in free animation
280300
trackLayer.masksToBounds = true
281301
trackLayer.backgroundColor = UIColor.clear.cgColor
282302
layer.addSublayer(trackLayer)
283303
trackLayer.addSublayer(leftTrackLayer)
284304
trackLayer.addSublayer(rightTrackLayer)
285305

286-
if let backgroundColor = tintColor {
287-
leadingTrackLayer.backgroundColor = backgroundColor.cgColor
288-
}
289-
rightTrackLayer.backgroundColor = maximumTrackTintColor.cgColor
290-
291306
// Ticks in between track and thumb
307+
ticksLayer.masksToBounds = true
308+
ticksLayer.backgroundColor = UIColor.clear.cgColor
292309
layer.addSublayer(ticksLayer)
310+
ticksLayer.addSublayer(rightTicksLayer) // reverse order, left covers right
311+
ticksLayer.addSublayer(leftTicksLayer)
293312

294313
// The thumb is its own CALayer, which brings in free animation
295314
layer.addSublayer(thumbLayer)
@@ -300,11 +319,6 @@ public class TGPDiscreteSlider:TGPSlider_INTERFACE_BUILDER {
300319

301320
func drawTicks() {
302321
ticksLayer.frame = bounds
303-
304-
if let tickColor = tickTintColor ?? tintColor {
305-
ticksLayer.backgroundColor = tickColor.cgColor
306-
}
307-
308322
let path = UIBezierPath()
309323

310324
switch tickComponentStyle {
@@ -363,10 +377,35 @@ public class TGPDiscreteSlider:TGPSlider_INTERFACE_BUILDER {
363377
break
364378
}
365379

366-
let maskLayer = CAShapeLayer()
367-
maskLayer.frame = trackLayer.bounds
368-
maskLayer.path = path.cgPath
369-
ticksLayer.mask = maskLayer
380+
leftTicksLayer.frame = {
381+
var frame = ticksLayer.bounds
382+
let tickWidth = (.rightToLeft == localeCharacterDirection)
383+
? -tickSize.width/2
384+
: tickSize.width/2
385+
frame.size.width = tickWidth + thumbAbscissa
386+
387+
return frame
388+
}()
389+
390+
leftTicksLayer.mask = {
391+
let maskLayer = CAShapeLayer()
392+
maskLayer.frame = ticksLayer.bounds
393+
maskLayer.path = path.cgPath
394+
return maskLayer
395+
}()
396+
397+
rightTicksLayer.frame = ticksLayer.bounds
398+
399+
rightTicksLayer.mask = {
400+
let maskLayer = CAShapeLayer()
401+
maskLayer.path = path.cgPath
402+
return maskLayer
403+
}()
404+
405+
if let backgroundColor = minimumTickTintColor ?? (minimumTrackTintColor ?? tintColor) {
406+
leadingTicksLayer.backgroundColor = backgroundColor.cgColor
407+
}
408+
trailingTicksLayer.backgroundColor = maximumTickTintColor?.cgColor ?? maximumTrackTintColor.cgColor
370409
}
371410

372411
func drawTrack() {

TGPControlsDemo/Podfile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,23 @@ platform :ios, '8.0'
33
use_frameworks!
44

55
target 'TGPControlsDemo-Pods' do
6-
pod 'TGPControls', :path => '../../TGPControls'
7-
#pod 'TGPControls'
6+
#pod 'TGPControls', :path => '../../TGPControls'
7+
pod 'TGPControls'
88
end
99

10+
# Failed to render and update auto layout status for UIViewController : dlopen(Cosmos.framework, 1): no suitable image found
11+
# https://github.com/CocoaPods/CocoaPods/issues/7606#issuecomment-381279098
12+
# https://stackoverflow.com/a/49936237/218152
13+
post_install do |installer|
14+
installer.pods_project.targets.each do |target|
15+
target.build_configurations.each do |config|
16+
config.build_settings.delete('CODE_SIGNING_ALLOWED')
17+
config.build_settings.delete('CODE_SIGNING_REQUIRED')
18+
end
19+
end
20+
installer.pods_project.build_configurations.each do |config|
21+
config.build_settings.delete('CODE_SIGNING_ALLOWED')
22+
config.build_settings.delete('CODE_SIGNING_REQUIRED')
23+
end
24+
end
1025

TGPControlsDemo/TGPControlsDemo.xcodeproj/project.pbxproj

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@
164164
DC56BDC01E46DEB900AAD0D9 /* Frameworks */,
165165
DC56BDC11E46DEB900AAD0D9 /* Resources */,
166166
A772C50843047EE677ADAF15 /* [CP] Embed Pods Frameworks */,
167-
3FF2E09CAFA7D92A488FACF7 /* [CP] Copy Pods Resources */,
168167
);
169168
buildRules = (
170169
);
@@ -258,21 +257,6 @@
258257
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
259258
showEnvVarsInLog = 0;
260259
};
261-
3FF2E09CAFA7D92A488FACF7 /* [CP] Copy Pods Resources */ = {
262-
isa = PBXShellScriptBuildPhase;
263-
buildActionMask = 2147483647;
264-
files = (
265-
);
266-
inputPaths = (
267-
);
268-
name = "[CP] Copy Pods Resources";
269-
outputPaths = (
270-
);
271-
runOnlyForDeploymentPostprocessing = 0;
272-
shellPath = /bin/sh;
273-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-TGPControlsDemo-Pods/Pods-TGPControlsDemo-Pods-resources.sh\"\n";
274-
showEnvVarsInLog = 0;
275-
};
276260
A772C50843047EE677ADAF15 /* [CP] Embed Pods Frameworks */ = {
277261
isa = PBXShellScriptBuildPhase;
278262
buildActionMask = 2147483647;
-336 Bytes
Loading
-148 Bytes
Loading
-147 Bytes
Loading
-154 Bytes
Loading
-69 Bytes
Loading
4 Bytes
Loading

TGPControlsDemo/TGPControlsDemo/Base.lproj/Main.storyboard

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,12 @@
379379
<userDefinedRuntimeAttribute type="size" keyPath="thumbShadowOffset">
380380
<size key="value" width="0.0" height="0.0"/>
381381
</userDefinedRuntimeAttribute>
382+
<userDefinedRuntimeAttribute type="color" keyPath="minimumTickTintColor">
383+
<color key="value" red="0.85098039219999999" green="0.0" blue="0.1058823529" alpha="1" colorSpace="calibratedRGB"/>
384+
</userDefinedRuntimeAttribute>
385+
<userDefinedRuntimeAttribute type="color" keyPath="maximumTickTintColor">
386+
<color key="value" red="0.85098039219999999" green="0.49424107142857143" blue="0.1058823529" alpha="1" colorSpace="calibratedRGB"/>
387+
</userDefinedRuntimeAttribute>
382388
</userDefinedRuntimeAttributes>
383389
</view>
384390
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="UIControlActions" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gID-5d-KDe">

0 commit comments

Comments
 (0)