I finally got it:
- I created a
NSSliderCell
subclass with a property@property float x
; - I overrode the
drawKnob
method and inside it I wrote:
-(void)drawKnob:(NSRect)knobRect{ self.x = knobRect.origin.x; }
- I dragged a
NSSlider
into my window (made it small, changed it's width to the window's width) and changed it's cell class to the one I created; - And then when the music is playing, every time a second goes by I do:
[_timeBarSlider setMinValue:0]; [_timeBarSlider setMaxValue:myTrack.duration]; [_timeBarSlider setDoubleValue:myPlayer.currentPosition]; [[_timeBarImageView animator] setFrame:NSMakeRect(_timeBarSliderCell.x, yourYCoordinate, yourWidth, yourHeight)];
_timerBarSlider
is the NSSlider I have in IB / _timerBarImageView
is the image view that contains the vertical image line / _timerBarSlderCell
is the NSSlider's cell (subclassed)
PS: the NSSlider is behind every object in that window, so that the user can't see it. You can't setHidden:YES
on it because the drawKnob
method will not be called.