/DragSteper

A draggable stepper controller for macOS / 适用于 macOS 的拖拽式数字步进器控件

Primary LanguageSwiftGNU Affero General Public License v3.0AGPL-3.0

DragSteper

A draggable stepper controller for macOS
[中文版本]

Introduction

This package lets you to use draggable steppers like on macOS 15 to control digital inputs on older macOS

Requirements

macOS 11.0+

Install

Add https://github.com/lihaoyun6/DragSteper to your project using Swift Package Manager in Xcode

Usage

First, import DragSteper into your code:

import DragSteper

Then you can:

import SwiftUI
import DragSteper

struct ContentView: View {
    @State var number: Int = 0
    @State var isPresented: Bool = false
    
    var body: some View {
        HStack {
            TextField("Test", value: $number, formatter: NumberFormatter())
                .popover(isPresented: $isPresented) {
                    DragSteper(value: $number)
                }
            Button("Edit") {
                isPresented = true
            }
        }.padding()
    }
}

When you click this button, a draggable stepper will pop up for fine-tuning the bound value.

You can also control the range using the minValue and maxValue parameters, or enable haptic feedback by adding haptic: true:

...
DragSteper(value: $number, minValue: 1, maxValue: 100, haptic: true)
...