You're not calling [super drawRect:rect]
and this causes the slide to never be drawn properly, however you should never override drawRect:
unless you need to perform custom drawing.
The right place where to initialize defaults is the designated initializer(s). Being UISlider
a subclass of UIView
, you need to override both -initWithFrame:
and -initWithCoder:
, to handle both the cases in which the slider is created programmatically or via a nib.
For instance
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self commonInit];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder]) {
[self commonInit];
}
return self;
}
- (void)commonInit {
self.minimumTrackTintColor = [ThemeManager minimumTrackTintColorForSlider];
self.maximumTrackTintColor = [ThemeManager maximumTrackTintColorForSlider];
self.minimumValueImage = [UIImage imageNamed:@"sliderLeftDot"];
self.maximumValueImage = [UIImage imageNamed:@"sliderRightDot"];
[self setThumbImage:[UIImage imageNamed:@"sliderCentrePiece"] forState:UIControlStateNormal];
}