Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for step slider & SPM #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Example/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down
6 changes: 6 additions & 0 deletions Example/Resources/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "slider_thumb.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
67 changes: 67 additions & 0 deletions Example/UI/CustomStepSliderController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import SliderController
import UIKit

class CustomStepSliderController: UIViewController, SliderControllerDelegate {

init() {
super.init(nibName: nil, bundle: nil)
}

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
embed(child: sliderController, in: view)
}

// MARK: - SliderControllerDelegate

func sliderDidTap(atValue value: Float) {
print("CustomStepSlider - did tap at value: \(value)") // TODO: Implement UI
}

func sliderValueDidChange(value: Float) {
print("CustomStepSlider - value did change: \(value)") // TODO: Implement UI
}

func sliderDidStartSwiping() {
print("CustomStepSlider - did start swiping") // TODO: Implement UI
}

func sliderDidEndSwiping() {
print("CustomStepSlider - did end swiping") // TODO: Implement UI
}

func sliderLabelForValue(label: String?) {
print("CustomStepSlider - label for value: \(label ?? "none")")
}

// MARK: - Private

private lazy var sliderController: SliderController = {
let slider = SliderController()
slider.unselectedTrackColor = UIColor(red: 0.13, green: 0.20, blue: 0.30, alpha: 1.0)
slider.selectedTrackColor = UIColor(red: 0.33, green: 0.11, blue: 0.73, alpha: 1.0)
slider.unselectedAnchorColor = UIColor(red: 0.13, green: 0.20, blue: 0.30, alpha: 1.0)
slider.selectedAnchorColor = UIColor(red: 0.33, green: 0.11, blue: 0.73, alpha: 1.0)
slider.thumbStyle = .custom(#imageLiteral(resourceName: "slider_thumb"))
slider.anchors = [0, 0.2, 0.4, 0.6, 0.8, 1.0]
slider.anchorRadius = 4
slider.trackHeight = 4
slider.labels = ["0.0", "0.2", "0.4", "0.6", "0.8", "1.0"]
slider.verticalLabelOffset = 15
slider.minimumValue = 0
slider.maximumValue = 1
slider.selectedLabelColor = .darkGray
slider.selectedLabelFont = UIFont.systemFont(ofSize: 14, weight: .regular)
slider.unselectedLabelColor = .lightGray
slider.unselectedLabelFont = UIFont.systemFont(ofSize: 14, weight: .regular)
slider.currentValueLabelColor = .gray
slider.currentValueLabelFont = UIFont.systemFont(ofSize: 14, weight: .bold)
slider.isStepSlider = true
slider.delegate = self
return slider
}()

required init?(coder: NSCoder) { nil }

}
63 changes: 63 additions & 0 deletions Example/UI/NonThumbSliderController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import SliderController
import UIKit

class NonThumbSliderController: UIViewController, SliderControllerDelegate {

init() {
super.init(nibName: nil, bundle: nil)
}

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
embed(child: sliderController, in: view)
}

// MARK: - SliderControllerDelegate

func sliderDidTap(atValue value: Float) {
print("NonThumbSlider - did tap at value: \(value)") // TODO: Implement UI
}

func sliderValueDidChange(value: Float) {
print("NonThumbSlider - value did change: \(value)") // TODO: Implement UI
}

func sliderDidStartSwiping() {
print("NonThumbSlider - did start swiping") // TODO: Implement UI
}

func sliderDidEndSwiping() {
print("NonThumbSlider - did end swiping") // TODO: Implement UI
}

func sliderLabelForValue(label: String?) {
print("NonThumbSlider - label for value: \(label ?? "none")")
}

// MARK: - Private

private lazy var sliderController: SliderController = {
let slider = SliderController()
slider.unselectedTrackColor = UIColor.red.withAlphaComponent(0.5)
slider.selectedTrackColor = .green
slider.unselectedAnchorColor = .red
slider.selectedAnchorColor = .green
slider.thumbStyle = .hidden
slider.anchors = [0, 0.3, 0.6, 1.0]
slider.anchorRadius = 14
slider.trackHeight = 7.5
slider.labels = ["A", "B", "C", "D"]
slider.horizontalLabelOffset = 0
slider.verticalLabelOffset = 0
slider.selectedLabelColor = .black
slider.selectedLabelFont = UIFont.systemFont(ofSize: 14, weight: .regular)
slider.unselectedLabelColor = .black
slider.unselectedLabelFont = UIFont.systemFont(ofSize: 14, weight: .regular)
slider.delegate = self
return slider
}()

required init?(coder: NSCoder) { nil }

}
22 changes: 22 additions & 0 deletions Example/UI/UIViewController+Embeding.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import UIKit

extension UIViewController {

func embed(child: UIViewController, in targetView: UIView) {
addChild(child)
targetView.addSubview(child.view)
child.view.translatesAutoresizingMaskIntoConstraints = false
child.view.topAnchor.constraint(equalTo: targetView.topAnchor).isActive = true
child.view.leftAnchor.constraint(equalTo: targetView.leftAnchor).isActive = true
child.view.rightAnchor.constraint(equalTo: targetView.rightAnchor).isActive = true
child.view.bottomAnchor.constraint(equalTo: targetView.bottomAnchor).isActive = true
child.didMove(toParent: self)
}

public func embed(_ childController: UIViewController, using embeddingMethod: (UIView) -> Void) {
addChild(childController)
embeddingMethod(childController.view)
childController.didMove(toParent: self)
}

}
67 changes: 17 additions & 50 deletions Example/UI/ViewController.swift
Original file line number Diff line number Diff line change
@@ -1,66 +1,33 @@
import UIKit
import SliderController

class ViewController: UIViewController, SliderControllerDelegate {
class ViewController: UIViewController {

override func loadView() {
view = UIView(frame: .zero)
view.backgroundColor = .white
embed(child: sliderController.controller, in: view)
view = customView
}

override func viewDidLoad() {
super.viewDidLoad()

sliderController.unselectedTrackColor = UIColor.red.withAlphaComponent(0.5)
sliderController.selectedTrackColor = .green
sliderController.unselectedAnchorColor = .red
sliderController.selectedAnchorColor = .green
sliderController.isThumbHidden = true
sliderController.anchors = [0, 0.3, 0.6, 1.0]
sliderController.anchorRadius = 15
sliderController.trackHeight = 7.5
sliderController.labels = ["A", "B", "C", "D"]
sliderController.horizontalLabelOffset = 0
sliderController.verticalLabelOffset = 0
sliderController.labelFont = UIFont.boldSystemFont(ofSize: 10)
sliderController.labelColor = UIColor.black
sliderController.delegate = self
}

let sliderController: SliderControlling = SliderController()

// MARK: SliderControllerDelegate

func sliderDidTap(atValue value: Float) {
print("Did tap at value: \(value)") // TODO: Implement UI
}

func sliderValueDidChange(value: Float) {
print("Slider value did change: \(value)") // TODO: Implement UI
}

func sliderDidStartSwiping() {
print("Slider did start swiping") // TODO: Implement UI
view.backgroundColor = .white
embedChildren()
}

func sliderDidEndSwiping() {
print("Slider did end swiping") // TODO: Implement UI
}
// MARK: - Private

}
private lazy var customView: UIStackView = {
let stackView = UIStackView()
stackView.axis = .vertical
stackView.distribution = .fillEqually
return stackView
}()

extension UIViewController {
private let customStepSliderController = CustomStepSliderController()
private let nonThumbSliderController = NonThumbSliderController()

func embed(child: UIViewController, in targetView: UIView) {
addChildViewController(child)
targetView.addSubview(child.view)
child.view.translatesAutoresizingMaskIntoConstraints = false
child.view.topAnchor.constraint(equalTo: targetView.topAnchor).isActive = true
child.view.leftAnchor.constraint(equalTo: targetView.leftAnchor).isActive = true
child.view.rightAnchor.constraint(equalTo: targetView.rightAnchor).isActive = true
child.view.bottomAnchor.constraint(equalTo: targetView.bottomAnchor).isActive = true
child.didMove(toParentViewController: self)
private func embedChildren() {
[customStepSliderController, nonThumbSliderController].forEach {
embed($0) { customView.addArrangedSubview($0) }
}
}

}
3 changes: 0 additions & 3 deletions Gemfile

This file was deleted.

72 changes: 0 additions & 72 deletions Gemfile.lock

This file was deleted.

15 changes: 15 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// swift-tools-version:5.5
import PackageDescription

let package = Package(
name: "SliderController",
platforms: [
.iOS("11.0"),
],
products: [
.library(name: "SliderController", targets: ["SliderController"]),
],
targets: [
.target(name: "SliderController", path: "Source"),
]
)
Loading