{"id":18031747,"url":"https://github.com/dagronf/dsfstepperview","last_synced_at":"2025-04-09T18:19:17.604Z","repository":{"id":47797766,"uuid":"311805984","full_name":"dagronf/DSFStepperView","owner":"dagronf","description":"A custom stepper text field for macOS and iOS, supporting Swift, Objective-C, SwiftUI and Catalyst","archived":false,"fork":false,"pushed_at":"2025-01-30T00:34:32.000Z","size":133,"stargazers_count":65,"open_issues_count":1,"forks_count":8,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T18:19:13.107Z","etag":null,"topics":["catalyst","ios","maccatalyst","macos","nsstepper","nstextfield","objective-c","stepper","swift","swiftui"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dagronf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-10T23:04:54.000Z","updated_at":"2025-01-30T00:34:40.000Z","dependencies_parsed_at":"2024-10-30T10:21:07.537Z","dependency_job_id":null,"html_url":"https://github.com/dagronf/DSFStepperView","commit_stats":{"total_commits":49,"total_committers":1,"mean_commits":49.0,"dds":0.0,"last_synced_commit":"d81b22a217b1ae0a1acb6c025fcbfdbf7bd6ad2e"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FDSFStepperView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FDSFStepperView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FDSFStepperView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FDSFStepperView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dagronf","download_url":"https://codeload.github.com/dagronf/DSFStepperView/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085325,"owners_count":21045139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["catalyst","ios","maccatalyst","macos","nsstepper","nstextfield","objective-c","stepper","swift","swiftui"],"created_at":"2024-10-30T10:10:39.382Z","updated_at":"2025-04-09T18:19:17.582Z","avatar_url":"https://github.com/dagronf.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DSFStepperView\n\nA custom stepper text field for macOS and iOS (Swift/SwiftUI/Objective-C/Catalyst).\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/dagronf/dagronf.github.io/blob/master/art/projects/DSFStepperView/DSFStepperView.jpg?raw=true\" alt=\"drawing\" width=\"406\"/\u003e\n  \u003cbr/\u003e\u003cbr/\u003e\n  \u003cimg src=\"https://github.com/dagronf/dagronf.github.io/blob/master/art/projects/DSFStepperView/indicators.png?raw=true\" alt=\"drawing\" width=\"406\"/\u003e\n  \u003cbr/\u003e\u003cbr/\u003e\n\u003cimg src=\"https://img.shields.io/github/v/tag/dagronf/DSFStepperView\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/macOS-10.13+-red\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/iOS-13+-blue\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/Swift-5.4-orange.svg\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/SwiftUI-2.0+-green\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/macCatalyst-13.0+-purple\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/License-MIT-lightgrey\"/\u003e\n\u003ca href=\"https://swift.org/package-manager\"\u003e\n   \u003cimg src=\"https://img.shields.io/badge/spm-compatible-brightgreen.svg?style=flat)\"/\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n## Why?\n\nI like the visual approach used with the SwiftUI settings pane, rather than having _really_ small hit targets via the conventional up/down stepper control on macOS.\n\n## Features\n\n* Support for macOS and iOS.\n* Cross-platform SwiftUI and Catalyst support for a consistent look.\n* `IBDesignable` support so you can see and configure your stepper views in Interface Builder.\n* Increment decrement buttons with repeat (click/press and hold to continuously increment/decrement)\n* Indicator bar to indicate the current fractional value of the control *(optional)*\n* Editable via keyboard *(optional)*\n* Empty field support (useful for items that are 'default' or 'inherited' values) *(optional)*\n* Set minimum/maximum and increment values. Support for float values (eg. increment by 0.01)\n* Font name/size/color\n* NumberFormatter support to display the value in the format you wish (for example, always showing 2 decimal places) *(optional)*\n* Specify a delegate to receive value change updates, or bind to the field's value.\n* Optional delegate to request tooltip strings depending on whether hovering over increment/decrement/text segments\n* Support for Combine publishing\n\n## Usage\n\nAdd `DSFStepperView` to your project via Swift Package Manager, or copy the sources in the Sources/DSFStepperView directly to your project\n\nDemos are available in the `Demo/` subfolder.\n\n### Via Interface Builder\n\nAdd a new `NSView` or `UIView` instance using Interface Builder, then change the class type to `DSFStepperView`\n\n### Programatically\n\n```swift\nlet stepperView = DSFStepperView(frame: .zero)\nstepperView.minimum = -1.0\nstepperView.maximum = 1.0\nstepperView.allowsEmpty = true\n...\n// Set the control's value to 0.5\nstepperView.floatValue = 0.5\n\n// Clear the control's value\nstepperView.floatValue = nil\n```\n\n## Receiving value changes\n\nThere are four methods for dynamically receiving value updates.\n\n### Receiving value changes via a delegate.\n\nImplement the protocol `DSFStepperViewDelegateProtocol` on an object and set it as the delegate for an instance of `DSFStepperView`. Updates to the value will be received via the\n\n```swift\nfunc stepperView(_ view: DSFStepperView, didChangeValueTo value: NSNumber?)\n```\n\ninterface.\n\n### Providing a change value block\n\nYou can provide a block to call via the `onValueChange` property on the stepper view.\n\n```swift\nself.stepper.onValueChange = { [weak self] newValue in\n   Swift.print(\"Ordinal value did change to \\(String(describing: newValue)) \")\n}\n```\n\n### Using the Combine framework on macOS 10.15, iOS 13 and later\n\nYou can use the Combine framework to subscribe to changes in the control.  On 10.15 and later the control exposes the publisher `publishedValue` from which you can subscribe to value changes.\n\n```swift\nself.cancellable = myStepper.publishedValue.sink(receiveValue: { currentValue in\n   if let c = currentValue {\n      print(\"stepper is currently at \\(c)\")\n   }\n   else {\n      print(\"stepper is currently empty\")\n   }\n})\n```\n\n### Binding to `numberValue` on an instance of the control.\n\nYou can use bindings to observe the `numberValue` member variable.\n\n```swift\nself.stepperObserver = self.observe(\\.stepper.numberValue, options: [.new], changeHandler: { (_, value) in\n   guard let val = value.newValue else { return }\n   Swift.print(\"\\(val)\")\n})\n```\n\n## Value Display Formatting\n\nIf you want to allow non-integer values (such as 0.5), you will need to provide a `NumberFormatter` instance to format and validate the value in the field. `DSFStepperView` provides a default NumberFormatter which provides integer only values in the range  (-∞ ... ∞) which you can override.\n\nUsing a number formatter also allows you to have a stepper that supports (for example) 1st, 2nd, 3rd, 4th when displaying.\n\n```swift\nlet format = NumberFormatter()\nformat.numberStyle = .decimal\n\n// Always display a single digit fractional value.\nformat.allowsFloats = true\nformat.minimumFractionDigits = 1\nformat.maximumFractionDigits = 1\n\nstepperView.numberFormatter = format\n```\n\nIn Interface Builder you can hook your instance's `numberFormatter` outlet to an instance of NumberFormatter in xib or storyboard.\n\n\n## Tooltips (macOS only)\n\nYou can specify a tooltip for the entire control the usual way using Interface Builder or programatically via \n\n```swift\nmyStepperInstance.toolTip = \"groovy!\"\n```\n\nYou can also provide individual tooltips for the components of the stepper via an optional function on the delegate.\n\n```swift\n@objc optional func stepperView(_ view: DSFStepperView, wantsTooltipTextforSegment segment: DSFStepperView.ToolTipSegment) -\u003e String?\n```\n\nUsing this method you can provide custom tooltips for the following stepper sections\n\n* The decrement button\n* The increment button\n* The value text field\n\n## Customizations\n\n### Properties\n\nThese properties can all be configured via Interface Builder or programatically.\n\n* `allowsEmpty` : Allow the field to be empty.  Useful if you want to display (for example) an 'inherited' or 'default' label (`Bool`)\n* `placeholder` : The placeholder string to use when the field is empty (`String`)\n* `minimum` : The minimum value to be allowed in the view (`CGFloat`)\n* `maximum` : The maximum value to be allowed in the view (`CGFloat`)\n* `increment` : The amount to increment or decrement the count when using the buttons (`CGFloat`)\n* `initialValue` : The initial value to be displayed in the field (useful only for @IBDesignable support) (`CGFloat`)\n* `fontName` : The name of the font displaying the value (eg. Menlo). Defaults to the system font if the fontName cannot be resolved on the system. (`String`)\n* `fontSize` : The size (in pts) of the font displaying the value (`CGFloat`)\n* `foregroundColor` : The color of the font displaying the value (`NSColor`/`UIColor`)\n* `indicatorColor` : The color to draw the fractional value bar at the bottom of the control (`NSColor`/`UIColor`)\n* `numberFormatter` : An optional number formatter for formatting/validating values in the view\n* `isEnabled` : Enable or disable the control\n* `font` : The font for the text field\n\n## SwiftUI\n\nA SwiftUI wrapper is available, supporting both iOS and macOS.  There is a demo project for iOS and macOS in the `Demo` subfolder.\n\n\u003cdetails\u003e\n\u003csummary\u003eExample\u003c/summary\u003e\n\n```swift\nstruct ContentView: View {\n\n   @State private var currentValue: CGFloat? = 23\n   @State private var isEnabled: Bool = true\n   \n   let configuration = DSFStepperView.SwiftUI.DisplaySettings(\n      minimum: 0, maximum: 100, increment: 1\n   )\n   let style = DSFStepperView.SwiftUI.Style(\n      font: DSFFont.systemFont(ofSize: 24, weight: .heavy),\n      indicatorColor: DSFColor.systemBlue)\n\n   var body: some View {\n      DSFStepperView.SwiftUI(\n         configuration: self.configuration,\n         style: self.style,\n         isEnabled: self.isEnabled,\n         floatValue: self.$currentValue,\n         onValueChange: { value in\n            Swift.print(\"New value is \\(String(describing: value))\")\n         }\n      )\n   }\n}\n```\n\n\u003c/details\u003e\n\n## History\n\n* `4.0.0`:\n  - Move to minimum macOS 10.13 target, Swift 5.4.\n  - Added inline SwiftUI previews for swiftui source.\n* `3.0.0`: Explicitly define both static and dynamic libraries in the package.\n* `2.0.1`: Fixed [issue 4](https://github.com/dagronf/DSFStepperView/issues/4) \n* `2.0.0`:\n  - Added iOS implementation for cross-platform compatibility (both SwiftUI and Catalyst support)\n  - Separated `floatValue` into `floatValue` (Swift only) and `numberValue` (an NSNumber for objc). If you have used bindings in your XIB that previously observed `floatValue` you will need to update them to use `numberValue` instead.\n  - Removed the ability to *set* the value via the publisher in Combine (was a dumb idea).\n* `1.1.4`: Added Objc demo, fixed delegate visibility\n* `1.1.3`: Fixed issue with default SwiftUI initializer not exported.\n* `1.1.2`: Some updates for accessibility\n* `1.1.1`: Fixed issue with Combine not available before 10.15\n* `1.1.0`: Added mouseover highlight for buttons, Combine publisher (10.15+), SwiftUI wrapper (10.15+).\n* `1.0.2`: Fixed Issue where 10.14 and earlier didn't display the value (NumberFormatter changes)\n* `1.0.1`: Fixed Bug #1 regarding disappearing button labels on Big Sur\n* `1.0.0`: Initial release\n\n## License\n\nMIT. Use it for anything you want, just attribute my work. Let me know if you do use it somewhere, I'd love to hear about it!\n\n```\nMIT License\n\nCopyright (c) 2021 Darren Ford\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdagronf%2Fdsfstepperview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdagronf%2Fdsfstepperview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdagronf%2Fdsfstepperview/lists"}