Another open source project for developers.
DejalIntervalPicker
is a custom Mac control similar to NSDatePicker
, but for time intervals or ranges.
This project was started several years ago for Time Out 2, but got put aside while I worked on contract projects. I've just finished it off and released it for others to enjoy. It will be making an appearance in Time Out 2 as of the next alpha release.
Requirements
- OS X 10.10 or later recommended, but should work back to 10.7.
- Objective-C language.
- ARC.
- Dependency: the DejalObject project.
Features
- A custom control with an amount or amount range, units, and stepper.
- Like
NSDatePicker
, editing components separately, with a stepper.
- Can set minimum and maximum amounts.
- Can get/set the interval as a
DejalInterval
, as individual values, or as a NSTimeInterval
.
- Can have either a single amount or a range of amounts.
- Can optionally filter the range to ensure the first amount is smaller (or equal to) the second one, or vice versa.
- Can control which units to include.
- Can navigate between components via Tab and Shift-Tab and left/right arrow keys, or clicking.
- Can type amounts just like in the date picker, and units with auto-completion.
- Can increment and decrement amounts and units via up/down arrow keys, +/- keys, or the stepper.
- Can increment/decrement in steps of 5 via Shift/Option/Ctrl and up/down arrow keys, or Page Up/Down.
- Can go to the first/last valid values via Home/End.
- Can display a drop-down menu of suggested legal amounts or units via the spacebar or clicking on the selected value.
- Supports regular, small and mini sizes.
- Supports properties, key-value coding, and bindings.
- Supports
IB_DESIGNABLE
and IBInspectable
, so the picker can be configured in IB.
- A demo project is included.
Usage
- Include the DejalIntervalPicker.h and DejalIntervalPicker.m files in your project. Also include at least DejalObject.h, DejalObject.m, DejalInterval.h and DejalInterval.m from the DejalObject project.
- In Interface Builder for your xib or storyboard, drag a custom view to your view or window.
- In the Identity inspector, change the Custom Class of the view to
DejalIntervalPicker
.
- In the Size inspector, add a Placeholder Intrinsic Size of 150 width and 22 height if using Auto Layout, or set the view to that size for auto-resizing.
- In the Attributes, configure the desired attributes like the using range, initial amounts, and which units to include.
- In your controller, you can also configure the picker via methods like
usingRange
, includeForever
, firstAmount
, and others; see the demo project for examples.
- Populate the picker value by setting the amount(s) and units, or setting the
interval
from a DejalInterval
instance.
- Get the picker value via the same properties: either amounts(s) and units directly, or the
interval
instance.
- See
DejalInterval
for several useful methods and properties, e.g. to get a string representation of the interval.
You can get the code and more information from the Dejal Open Source page.