Coder Social home page Coder Social logo

kefaxoo / slidercontrol Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alexchekel1337/slidercontrol

0.0 0.0 0.0 642 KB

A small Swift Package aiming to recreate volume and track sliders found in Apple Music

License: MIT License

Swift 100.00%

slidercontrol's Introduction

SliderControl

SliderControl is a small Swift Package aiming to recreate volume and track sliders found in Apple Music on iOS 16 and later.

Default configuration

Usage

SliderControl maintains an API similar to built-in UISlider. It has the same properties, like value and isContinuous. Progress observation is done the same way, by adding a target and an action:

sliderControl.addTarget(self, action: #selector(sliderValueChanged), for: .valueChanged)

Customization

There are a few properties to customize SliderControl's appearance:

  • defaultTrackColor sets a track color for default state;
  • defaultProgressColor sets a progress color for default state;
  • enlargedTrackColor sets a track color for state when user actively changing the progress;
  • enlargedProgressColor sets a progress color for state when user actively changing the progress.

The default value of enlargedTrackColor and enlargedProgressColor is nil, so the slider won't change color upon interaction in its default configuration. However, by setting different colors, you can configure the slider to change its appearance when user interacts with it. Here's an example:

Different colors

sliderControl.defaultTrackColor = .quaternarySystemFill
sliderControl.defaultProgressColor = .tertiarySystemFill
sliderControl.enlargedTrackColor = .secondarySystemFill
sliderControl.enlargedProgressColor = .systemFill

By default SliderControl provides haptic feedback when value reaches lower and upper bounds. This behavior can be changed by setting providesHapticFeedback property to false. Types of haptic feedback can also be changed by subclassing SliderControl:

class MySliderControl: SliderControl {
    override var feedbackGenerator: UIFeedbackGenerator {
        return UINotificationFeedbackGenerator()
    }

    override func provideHapticFeedbackForMinimumValue() {
        (feedbackGenerator as? UINotificationFeedbackGenerator)?.notificationOccurred(.error)
    }

    override func provideHapticFeedbackForMaximumValue() {
        (feedbackGenerator as? UINotificationFeedbackGenerator)?.notificationOccurred(.success)
    }
}

RTL Support

SliderControl supports right-to-left languages.

RTL Example

Requirements

  • iOS 13+
  • Swift 5.8

slidercontrol's People

Contributors

alexchekel1337 avatar kefaxoo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.