问题描述
我在 NSSliderCell
上搜索了一些代码,但我找不到一种方法来做我正在寻找的内容。
我想创建这样的东西(白线是滑块旋钮,1像素宽):
I've searched around for some code on NSSliderCell
but I can't find a way to do what I'm looking for.
I'd like to create something like this (where the white line is the slider knob, 1 pixel width):
我将使用这个作为音乐曲目的时间条,所以它将每秒这就是为什么我想使用 NSSlider
来简化操作)。
我需要做什么来做一个滑块,有一个透明的中间栏,类似于上面的图像?
PS:它不会是可触摸的,它只是为了显示。
I'm going to use this for the time bar of a music track, so it's going to move every second (that's why I want to use a NSSlider
to make things easy).
What do I need to do to make a slider, with a transparent middle bar, similar to the image above?
PS: It's not going to be touchable, it's just for display.
推荐答案
我终于得到了:
- 我创建了一个
NSSliderCell
子类的属性@property float x
; - 我覆盖了
drawKnob
方法和里面我写的:
- I created a
NSSliderCell
subclass with a property@property float x
; - I overrode the
drawKnob
method and inside it I wrote:
- 我将一个
NSSlider
窗口(使它变小,将宽度改为窗口的宽度),并将其单元格类更改为我创建的单元格类; - 然后当音乐播放时,每次一秒钟我这样做:
- 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
是NSSlider我在IB / _timerBarImageView
是包含垂直图像行的图像视图/ _timerBarSlderCell
是NSSlider的单元格(子类)
PS:NSSlider在该窗口中的每个对象后面,以便用户看不到它。您不能 setHidden:YES
,因为 drawKnob
方法不会被调用。
_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.
这篇关于如何创建一个透明的中间栏和自定义旋钮大小的自定义NSSlider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!