Skip to content

Commit

Permalink
[Shadow Elevation] Changed slider to be discrete to make it more clea…
Browse files Browse the repository at this point in the history
…r that the named labels are for specific values of the slider. (#3741)

https://www.pivotaltracker.com/story/show/157297961
  • Loading branch information
randallli authored and ianegordon committed May 7, 2018
1 parent 8b4c293 commit f6e04eb
Showing 1 changed file with 11 additions and 3 deletions.
Expand Up @@ -25,7 +25,7 @@
static const CGFloat kShadowElevationsMax = 24.f;
static const CGFloat kShadowElevationsSliderFrameHeight = 27.0f;

@interface ShadowElevationsPointsView : UIView
@interface ShadowElevationsPointsView : UIView <MDCSliderDelegate>

@property(nonatomic) ShadowElevationsPointsLabel *paper;
@property(nonatomic) UILabel *elevationLabel;
Expand Down Expand Up @@ -60,7 +60,10 @@ - (id)initWithFrame:(CGRect)frame {
CGRect sliderRect = CGRectMake(margin, 140.f, frame.size.width - margin * 2,
kShadowElevationsSliderFrameHeight);
MDCSlider *sliderControl = [[MDCSlider alloc] initWithFrame:sliderRect];
sliderControl.value = kShadowElevationsDefault / kShadowElevationsMax;
sliderControl.numberOfDiscreteValues = (NSUInteger) kShadowElevationsMax + 1;
sliderControl.maximumValue = kShadowElevationsMax;
sliderControl.value = kShadowElevationsDefault;
sliderControl.delegate = self;
sliderControl.autoresizingMask =
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin);
Expand All @@ -72,8 +75,13 @@ - (id)initWithFrame:(CGRect)frame {
return self;
}

- (NSString *)slider:(MDCSlider *)slider displayedStringForValue:(CGFloat)value {
NSInteger points = (NSInteger)round(value);
return [NSString stringWithFormat:@"%ld pt", (long)points];
}

- (void)sliderValueChanged:(MDCSlider *)slider {
NSInteger points = (NSInteger)round(slider.value * kShadowElevationsMax);
NSInteger points = (NSInteger)round(slider.value);
_paper.text = [NSString stringWithFormat:@"%ld pt", (long)points];
[_paper setElevation:points];
if (points == MDCShadowElevationNone) {
Expand Down

0 comments on commit f6e04eb

Please sign in to comment.