iOS 滑塊:TTRangeSlider

jopen 9年前發布 | 28K 次閱讀 iOS開發 移動開發 TTRangeSlider

TTRangeSlider 是一個滑塊,風格類似于 UISlider,但是它能讓你選擇最大最小值范圍。

Installation

TTRangeSlider is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "TTRangeSlider"

Note that this control uses IB_DESIGNABLE, so for it to work well and not get warnings in Interface Builder, you should use the latest version of cocoa pods, and add theuse_frameworks!line. So your podfile may look something like

source ‘https://github.com/CocoaPods/Specs.git' use_frameworks!  pod “TTRangeSlider”

Usage

Add the TTRangeSlider like you would with any other UIControl. Either:

  • Add a view in your storyboard/class and change it’s type toTTRangeSlider. As long as you’re using >= XCode6 you can now use this control like any other, you can set all the properties in the Attributes Inspector and see a live preview:

Interface Builder Screenshot

or

  • Create theTTRangeSliderin code using[TTRangeSlider alloc] init]then add it as a subview to your code and set the relevant autolayout properties or frame.

The default slider ranges from 0->100 and has 10 preselected as the minimum, and 90 as the maximum.

Values that the user has selected are exposed using theselectedMinimumandselectedMaximumproperties. You can also use these properties to change the selected values programatically if you wish.

Other customisation of the control is done using the following properties:

tintColor

The tintColor property (which you can also set in Interface Builder) sets the overall colour of the control, including the colour of the line, the two handles, and the labels.

It is safe to change thetintColorat any time, if the control is currently visible the colour change will be animated into the new colour.

minValue

The minimum possible value to select in the range

maxValue

The maximum possible value to select in the range

selectedMinimum

The preselected minumum value (note: This should be less than the selectedMaximum)

selectedMaximum

The preselected maximum value (note: This should be greater than the selectedMinimum)

numberFormatterOverride

Each handle in the slider has a label above it showing the current selected value. By default, this is displayed as a decimal format.

You can override this default here by supplying your own NSNumberFormatter. For example, you could supply an NSNumberFormatter that has a currency style, or a prefix or suffix.

If this property is nil, the default decimal format will be used. Note: If you want no labels at all, set this value to be(NSNumberFormatter *)[NSNull null](as opposed to nil), to specifically mark that you want no labels

minLabelColour

The colour of the minimum value text label. If not set, the default is the tintColor.

maxLabelColour

The colour of the maximum value text label. If not set, the default is the tintColor.

disableRange

If true, the control will mimic a normal slider and have only one handle rather than a range.

In this case, the selectedMinValue will be not functional anymore. Use selectedMaxValue instead to determine the value the user has selected.

項目主頁:http://www.baiduhome.net/lib/view/home/1428630326656

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!