Swift-VPSwitchToggle

1.0.2

VansonLeung/Swift-VPSwitchToggle

What's New

2023-07-13T05:49:16Z

Swift-VPSwitchToggle

This package is the alternative of "https://github.com/VansonLeung/SwiftUI-VPSwitchToggle" but written in Swift UIKit.

Fully customizable UISwitch alternative.

Supports iOS 11 or above

Supports the following background transition animations:

  • Fade
  • Horizontal
  • HorizontalReverse
  • Vertical
  • VerticalReverse

Demo Video

dSimulator.Screen.Recording.-.iPhone.14.Pro.-.2023-07-13.at.13.23.18.mov

Installation

Install Swift Package in SPM:

.package(url: "https://github.com/VansonLeung/Swift-VPSwitchToggle.git", from: "1.0.1")

Usage

Create UI by interface builder:

image image

Create UI by code:

        let tg = VPSwitchToggle(frame: CGRect(x: 0, y: 0, width: 0, height: csv?.frame.height ?? 0))
        tg.isOn = true
        tg.widgetForegroundMargin = 6
        tg.state_on_backgroundImage = .init(named: "f_switch_bg_moon")
        tg.state_on_backgroundColor = .init(red: 29.0/255.0, green: 32.0/255.0, blue: 47.0/255.0, alpha: 1.0)
        tg.state_on_foregroundImage = .init(named: "f_switch_button_moon")
        tg.state_on_foregroundColor = .init(red: 203.0/255.0, green: 207.0/255.0, blue: 215.0/255.0, alpha: 1.0)
        tg.state_off_backgroundImage = .init(named: "f_switch_bg_sun")
        tg.state_off_backgroundColor = .init(red: 71.0/255.0, green: 125.0/255.0, blue: 182.0/255.0, alpha: 1.0)
        tg.state_off_foregroundImage = .init(named: "f_switch_button_sun")
        tg.state_off_foregroundColor = .init(red: 244.0/255.0, green: 201.0/255.0, blue: 81.0/255.0, alpha: 1.0)
        tg.backgroundImageOrder = VPSwitchToggle.BackgroundImageOrder.verticalReversed.rawValue
        tg.addTarget(self, action: #selector(onVPSwitchToggleValueChanged(me: )), for: .valueChanged)
        stackView?.addArrangedSubview(tg)

Description

  • Swift Tools 5.8.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Oct 20 2024 05:51:58 GMT-0900 (Hawaii-Aleutian Daylight Time)