Skip to content

Commit cdc746a

Browse files
author
Ian Gordon
committed
Add support for interface builder to MDCSlider.
Summary: Move common initialization to commonInit. Add initWithCoder method. Reviewers: junius, #material_components_ios_owners, cjcox Reviewed By: #material_components_ios_owners, cjcox Subscribers: cjcox Projects: #material_components_ios Differential Revision: http://codereview.cc/D131
1 parent 7175338 commit cdc746a

File tree

1 file changed

+37
-25
lines changed

1 file changed

+37
-25
lines changed

components/Slider/src/MDCSlider.m

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,47 @@ @implementation MDCSlider {
3636
- (instancetype)initWithFrame:(CGRect)frame {
3737
self = [super initWithFrame:frame];
3838
if (self) {
39-
CGRect trackFrame = CGRectInset(frame, 8.f, 0.f);
40-
41-
_thumbTrack = [[MDCThumbTrack alloc] initWithFrame:trackFrame onTintColor:[[self class] defaultColor]];
42-
_thumbTrack.delegate = self;
43-
_thumbTrack.disabledTrackHasThumbGaps = YES;
44-
_thumbTrack.trackEndsAreInset = YES;
45-
_thumbTrack.thumbRadius = kSliderThumbRadius;
46-
_thumbTrack.thumbMaxRippleRadius = kSliderThumbMaxRippleRadius;
47-
_thumbTrack.trackOffColor = [[self class] defaultTrackOffColor];
48-
[_thumbTrack addTarget:self
49-
action:@selector(thumbTrackValueChanged:)
50-
forControlEvents:UIControlEventValueChanged];
51-
[_thumbTrack addTarget:self
52-
action:@selector(thumbTrackTouchDown:)
53-
forControlEvents:UIControlEventTouchDown];
54-
[_thumbTrack addTarget:self
55-
action:@selector(thumbTrackTouchUpInside:)
56-
forControlEvents:UIControlEventTouchUpInside];
57-
[_thumbTrack addTarget:self
58-
action:@selector(thumbTrackTouchUpOutside:)
59-
forControlEvents:UIControlEventTouchUpOutside];
60-
[_thumbTrack addTarget:self
61-
action:@selector(thumbTrackTouchCanceled:)
62-
forControlEvents:UIControlEventTouchCancel];
63-
[self addSubview:_thumbTrack];
39+
[self commonInit];
6440
}
6541
return self;
6642
}
6743

44+
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
45+
self = [super initWithCoder:aDecoder];
46+
if (self) {
47+
[self commonInit];
48+
}
49+
return self;
50+
}
51+
52+
- (void)commonInit {
53+
CGRect trackFrame = CGRectInset(self.frame, 8.f, 0.f);
54+
55+
_thumbTrack = [[MDCThumbTrack alloc] initWithFrame:trackFrame onTintColor:[[self class] defaultColor]];
56+
_thumbTrack.delegate = self;
57+
_thumbTrack.disabledTrackHasThumbGaps = YES;
58+
_thumbTrack.trackEndsAreInset = YES;
59+
_thumbTrack.thumbRadius = kSliderThumbRadius;
60+
_thumbTrack.thumbMaxRippleRadius = kSliderThumbMaxRippleRadius;
61+
_thumbTrack.trackOffColor = [[self class] defaultTrackOffColor];
62+
[_thumbTrack addTarget:self
63+
action:@selector(thumbTrackValueChanged:)
64+
forControlEvents:UIControlEventValueChanged];
65+
[_thumbTrack addTarget:self
66+
action:@selector(thumbTrackTouchDown:)
67+
forControlEvents:UIControlEventTouchDown];
68+
[_thumbTrack addTarget:self
69+
action:@selector(thumbTrackTouchUpInside:)
70+
forControlEvents:UIControlEventTouchUpInside];
71+
[_thumbTrack addTarget:self
72+
action:@selector(thumbTrackTouchUpOutside:)
73+
forControlEvents:UIControlEventTouchUpOutside];
74+
[_thumbTrack addTarget:self
75+
action:@selector(thumbTrackTouchCanceled:)
76+
forControlEvents:UIControlEventTouchCancel];
77+
[self addSubview:_thumbTrack];
78+
}
79+
6880
#pragma mark - ThumbTrack passthrough methods
6981

7082
- (void)setTrackBackgroundColor:(UIColor *)trackBackgroundColor {

0 commit comments

Comments
 (0)