Git Product home page Git Product logo

amslider's Introduction

AMSlider

Slider like in Apple Music from iOS 16+

Requirements

  • An iPhone/iPad running iOS 16.0+

Installation

Swift Package Manager

Using XCode UI: Project Settings -> Swift Packages and add AMSlider from there

Usage

Simple example using NSLayoutConstraint:

lazy var constraints: [NSLayoutConstraint] = {
    return [
        self.amSlider.centerYAnchor.constraint(equalTo: self.view.centerYAnchor),
        self.amSlider.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.width - 20),
        self.amSlider.heightAnchor.constraint(equalToConstant: 10),
        self.amSlider.centerXAnchor.constraint(equalTo: self.view.centerXAnchor)
    ]
}()

lazy var amSlider: CustomAMSlider = {
    let slider = CustomAMSlider(
        cornerRadius: 5,
        width: UIScreen.main.bounds.width - 20
    )
}()

override func viewDidLoad() {
    super.viewDidLoad()
    self.view.addSubview(amSlider)
    self.view.translatesAutoresizingMaskIntoConstraints = false
    NSLayoutConstraint.activate(constraints)

    amSlider.setTintColor(tintColor: UIColor.systemPurple)
    amSlider.beginTapClosure = {
        self.constraints[1].isActive = false
        self.constraints[2].isActive = false
        
        self.constraints[1] = self.amSlider.widthAnchor.constraint(equalToConstant: self.amSlider.frame.width + 10)
        self.constraints[2] = self.amSlider.heightAnchor.constraint(equalToConstant: self.amSlider.frame.height + 10)
        
        self.constraints[1].isActive = true
        self.constraints[2].isActive = true
        
        UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .curveEaseInOut) {
            self.view.layoutIfNeeded()
        }
    }

    amSlider.endTapClosure = {
        self.constraints[1].isActive = false
        self.constraints[2].isActive = false
        
        self.constraints[1] = self.amSlider.widthAnchor.constraint(equalToConstant: self.amSlider.frame.width - 10)
        self.constraints[2] = self.amSlider.heightAnchor.constraint(equalToConstant: self.amSlider.frame.height - 10)
        
        self.constraints[1].isActive = true
        self.constraints[2].isActive = true
        
        UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .curveEaseInOut) {
            self.view.layoutIfNeeded()
        }
    }
}

amslider's People

Contributors

kefaxoo avatar

Watchers

 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.