Will Larche 1080e89422 [Documentation] Putting Swift snippets before Objc (#960)
* [ActivityIndicator] Swift first in README

* [AnimationTiming] Swift first in readme.

* [AppBar] Swift first in readme.

* [ButtonBar] Swift first in readme.

* [Buttons] Swift first in readme.

* [CollectionLayoutAttributes] Swift first in readme

* [Collections] Swift first in readme.

* [Dialogs] Swift first in readme.

* [FeatureHighlight] Swift first in readme.

* [FlexibleHeader] Swift first in readme.

* [FontDiskLoader] Swift first in readme.

* [HeaderStackView] Swift first in readme.

* [Ink] Swift first in readme.

* [NavigationBar] Swift first in readme.

* [OverlayWindow] Adding missing site comments. Swift first in readme.

* [PageControl] Swift first in readme.

* [Palettes] Swift first in readme.

* [ProgressView] Swift first in readme.

* [RobotoFontLoader] Swift first in readme.

* [ShadowElevations] Swift first in readme.

* [ShadowLayer] Swift first in readme.

* [Slider] Swift first in readme.

* [Snackbar] Swift first in readme.

* [SpritedAnimationView] Swift first in readme.

* [Switch] Swift first in readme.

* [Typography] Swift first in readme.

* [ShadowLayer] Reducing font size in readme.

* [Switch] Reducing font size in readme.
2016-12-07 10:31:34 -05:00
..
2016-11-18 14:24:23 -05:00

Slider

Slider

The MDCSlider object is a material design control used to select a value from a continuous range or discrete set of values.

Design Specifications

API Documentation


Installation

Requirements

  • Xcode 7.0 or higher.
  • iOS SDK version 7.0 or higher.

Installation with CocoaPods

To add this component to your Xcode project using CocoaPods, add the following to your Podfile:

pod 'MaterialComponents/Slider'

Then, run the following command:

pod install

Usage

Importing

Before using Slider, you'll need to import it:

Swift

import MaterialComponents

Objective-C

#import "MaterialSlider.h"

Standard usage

MDCSlider can be be used like a standard UIControl.

Swift

override func viewDidLoad() {
  let slider = MDCSlider(frame: CGRectMake(50, 50, 100, 27))
  slider.addTarget(self,
      action: Selector("didChangeSliderValue:"),
      forControlEvents: .ValueChanged)
  view.addSubview(slider)
}

func didChangeSliderValue(senderSlider:MDCSlider) {
  NSLog("Did change slider value to: %@", senderSlider.value)
}

Objective C


- (void)viewDidLoad {
  MDCSlider *slider = [[MDCSlider alloc] initWithFrame:CGRectMake(50, 50, 100, 27)];
  [slider addTarget:self
                action:@selector(didChangeSliderValue:)
      forControlEvents:UIControlEventValueChanged];
  [self.view addSubview:slider];
}

- (void)didChangeSliderValue:(MDCSlider *)slider {
  NSLog(@"did change %@ value: %f", NSStringFromClass([slider class]), slider.value);
}

The differences between the UISlider class and the MDCSlider class:

Does not have api to:

  • set right and left icons
  • set the thumb image
  • set the right and left track images (for a custom track)
  • set the right (background track) color

Same features:

  • set color for thumb via @c thumbColor
  • set color of track via @c trackColor

New features:

  • making the slider a snap to discrete values via property numberOfDiscreteValues.