Skip to content

Commit

Permalink
add defaults to initWithCoder:
Browse files Browse the repository at this point in the history
Fix #27
  • Loading branch information
spromicky committed Dec 29, 2018
1 parent add9f61 commit 8458dbd
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions StepSlider/source/StepSlider/StepSlider.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,11 @@ @implementation StepSlider

#pragma mark - Init

- (instancetype)init
{
self = [super init];
if (self) {
[self generalSetup];
}
return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_index = 2;
[self generalSetup];
}
return self;
Expand All @@ -77,7 +69,7 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self addLayers];
[self generalSetup];
}
return self;
}
Expand All @@ -104,17 +96,32 @@ - (void)generalSetup
{
[self addLayers];

_maxCount = 4;
_index = 2;
_trackHeight = 4.f;
_trackCircleRadius = 5.f;
_sliderCircleRadius = 12.5f;
_trackColor = [UIColor colorWithWhite:0.41f alpha:1.f];
_sliderCircleColor = [UIColor whiteColor];
_labelOffset = 20.f;
_labelColor = [UIColor whiteColor];
if (_maxCount == 0) {
_maxCount = 4;
}
if (_trackHeight == 0.f) {
_trackHeight = 4.f;
}
if (_trackCircleRadius == 0.f) {
_trackCircleRadius = 5.f;
}
if (_sliderCircleRadius == 0.f) {
_sliderCircleRadius = 12.5f;
}
if (_labelOffset == 0.f) {
_labelOffset = 20.f;
}
if (!_trackColor) {
_trackColor = [UIColor colorWithWhite:0.41f alpha:1.f];
}
if (!_sliderCircleColor) {
_sliderCircleColor = [UIColor whiteColor];
}
if (!_labelColor) {
_labelColor = [UIColor whiteColor];
}

[self updateMaxRadius];

[self setNeedsLayout];
}

Expand Down

0 comments on commit 8458dbd

Please sign in to comment.