forked from yonat/MultiSlider
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
221 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// MultiSliderDemo.swift | ||
// | ||
// Copyright © 2019 Yonat Sharon. All rights reserved. | ||
// | ||
|
||
// swiftlint:disable numbers_smell | ||
#if canImport(SwiftUI) | ||
|
||
import MultiSlider | ||
import SwiftUI | ||
|
||
@available(iOS 13.0, *) | ||
struct MultiValueSliderDemo: View { | ||
@State private var doubleValue: [CGFloat] = [1, 3] | ||
@State private var tripleValue: [CGFloat] = [1, 3, 5] | ||
|
||
var body: some View { | ||
VStack(alignment: .center) { | ||
MultiValueSlider( | ||
value: $doubleValue, | ||
maximumValue: 5, | ||
snapStepSize: 1, | ||
orientation: .horizontal, | ||
outerTrackColor: .lightGray | ||
) | ||
.frame(width: 320) | ||
.scaledToFit() | ||
|
||
MultiValueSlider( | ||
value: $tripleValue, | ||
maximumValue: 5, | ||
valueLabelPosition: .top, | ||
orientation: .horizontal | ||
) | ||
.accentColor(.purple) | ||
|
||
HStack { | ||
MultiValueSlider( | ||
value: $doubleValue, | ||
maximumValue: 5, | ||
valueLabelPosition: .right, | ||
orientation: .vertical, | ||
valueLabelColor: .systemGreen, | ||
valueLabelFont: .boldSystemFont(ofSize: 20), | ||
trackWidth: 12 | ||
) | ||
.accentColor(.green) | ||
|
||
MultiValueSlider( | ||
value: $tripleValue, | ||
maximumValue: 5, | ||
orientation: .vertical, | ||
outerTrackColor: .lightGray, | ||
trackWidth: 12 | ||
) | ||
} | ||
} | ||
.padding() | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// | ||
// MultiValueSlider.swift | ||
// | ||
// Created by Yonat Sharon on 16/09/2019. | ||
// | ||
|
||
#if canImport(SwiftUI) | ||
|
||
import SweeterSwift | ||
import SwiftUI | ||
|
||
/// Slider clone with multiple thumbs and values, range highlight, optional snap intervals, optional value labels. | ||
@available(iOS 13.0, *) public struct MultiValueSlider: UIViewRepresentable { | ||
public typealias UIViewType = MultiSlider | ||
private let uiView = MultiSlider() | ||
|
||
@Binding var value: [CGFloat] | ||
|
||
public init( | ||
value: Binding<[CGFloat]>, | ||
minimumValue: CGFloat? = nil, | ||
maximumValue: CGFloat? = nil, | ||
isContinuous: Bool? = nil, | ||
snapStepSize: CGFloat? = nil, | ||
isHapticSnap: Bool? = nil, | ||
valueLabelPosition: NSLayoutConstraint.Attribute? = nil, | ||
isValueLabelRelative: Bool? = nil, | ||
orientation: NSLayoutConstraint.Axis? = nil, | ||
outerTrackColor: UIColor? = nil, | ||
valueLabelColor: UIColor? = nil, | ||
valueLabelFont: UIFont? = nil, | ||
thumbImage: UIImage? = nil, | ||
showsThumbImageShadow: Bool? = nil, | ||
minimumImage: UIImage? = nil, | ||
maximumImage: UIImage? = nil, | ||
trackWidth: CGFloat? = nil, | ||
hasRoundTrackEnds: Bool? = nil, | ||
distanceBetweenThumbs: CGFloat? = nil, | ||
keepsDistanceBetweenThumbs: Bool? = nil, | ||
valueLabelFormatter: NumberFormatter? = nil | ||
) { | ||
_value = value | ||
|
||
uiView.minimumValue =? minimumValue | ||
uiView.maximumValue =? maximumValue | ||
uiView.isContinuous =? isContinuous | ||
uiView.snapStepSize =? snapStepSize | ||
uiView.isHapticSnap =? isHapticSnap | ||
uiView.valueLabelPosition =? valueLabelPosition | ||
uiView.isValueLabelRelative =? isValueLabelRelative | ||
uiView.orientation =? orientation | ||
uiView.outerTrackColor =? outerTrackColor | ||
uiView.valueLabelColor =? valueLabelColor | ||
uiView.valueLabelFont =? valueLabelFont | ||
uiView.thumbImage =? thumbImage | ||
uiView.showsThumbImageShadow =? showsThumbImageShadow | ||
uiView.minimumImage =? minimumImage | ||
uiView.maximumImage =? maximumImage | ||
uiView.trackWidth =? trackWidth | ||
uiView.hasRoundTrackEnds =? hasRoundTrackEnds | ||
uiView.distanceBetweenThumbs =? distanceBetweenThumbs | ||
uiView.keepsDistanceBetweenThumbs =? keepsDistanceBetweenThumbs | ||
uiView.valueLabelFormatter =? valueLabelFormatter | ||
} | ||
|
||
public func makeUIView(context: UIViewRepresentableContext<MultiValueSlider>) -> MultiSlider { | ||
uiView.addTarget(context.coordinator, action: #selector(Coordinator.valueChanged), for: .valueChanged) | ||
return uiView | ||
} | ||
|
||
public func updateUIView(_ uiView: MultiSlider, context: UIViewRepresentableContext<MultiValueSlider>) { | ||
uiView.value = value | ||
} | ||
|
||
public func makeCoordinator() -> Coordinator { | ||
Coordinator(self) | ||
} | ||
|
||
public class Coordinator: NSObject { | ||
let parent: MultiValueSlider | ||
|
||
init(_ parent: MultiValueSlider) { | ||
self.parent = parent | ||
} | ||
|
||
@objc func valueChanged(_ sender: MultiSlider) { | ||
parent.value = sender.value | ||
} | ||
} | ||
} | ||
|
||
#endif |