Slider 滑块(Slider) macos

Volume

标本可交互 —— 点点看。Specimen is live — try it.

Anatomy — every part, named解剖 —— 每个部件的名字

  1. 1 Knob (thumb)滑钮(Knob/thumb) NSSlider.knobThickness

    “The round dot you drag” is the knob — AppKit calls it the knob; the web calls the same thing a thumb.

    “你拖的那个圆点”就是滑钮 —— AppKit 叫它 knob;Web 上同一个东西叫 thumb。

    Prompt fragmentPrompt 片段

    the round draggable knob of an NSSlider (the web calls it the thumb)

    NSSlider 上可拖动的圆形滑钮(Web 称之为 thumb)

  2. 2 Filled track已填充轨道(Filled track) Slider + .tint

    “The blue part of the line before the knob” is the filled side of the track — it shows how far along the range the value sits.

    “滑钮之前线上蓝色的那段”就是轨道的已填充侧 —— 它显示值在范围内走了多远。

    Prompt fragmentPrompt 片段

    the tinted leading portion of a slider track, from the minimum up to the knob (SwiftUI: Slider with .tint)

    滑块轨道从最小值到滑钮的染色前段(SwiftUI:Slider 配 .tint)

  3. 3 Track轨道(Track) NSSlider.SliderType.linear

    “The groove the dot slides along” is the track — the full range, end to end.

    “圆点滑行的那条凹槽”就是轨道 —— 从头到尾的整个范围。

    Prompt fragmentPrompt 片段

    the full-width groove of a linear NSSlider that the knob travels along

    线性 NSSlider 上滑钮通行的整条全宽凹槽

  4. 4 Tick marks刻度线(Tick marks) NSSlider.numberOfTickMarks

    “The little lines under the slider” are tick marks — with allowsTickMarkValuesOnly the knob only lands on them.

    “滑块下面的小线”就是刻度线 —— 配上 allowsTickMarkValuesOnly,滑钮只落在刻度上。

    Prompt fragmentPrompt 片段

    tick marks below an NSSlider (numberOfTickMarks, tickMarkPosition = .below), snapping via allowsTickMarkValuesOnly

    NSSlider 下方的刻度线(numberOfTickMarks,tickMarkPosition = .below),用 allowsTickMarkValuesOnly 吸附

Prompt — paste into your agentPrompt —— 直接粘贴给你的代理

Use a native macOS slider — NSSlider (SwiftUI: Slider(value:in:step:)): horizontal linear style, round knob, the leading side of the track tinted with the accent color. For discrete values add tick marks below with numberOfTickMarks and tickMarkPosition = .below, and snap the knob to them with allowsTickMarkValuesOnly = true. Set isContinuous = true so the value updates while dragging.

使用原生 macOS 滑块 —— NSSlider(SwiftUI:Slider(value:in:step:)):水平线性样式、圆形滑钮,轨道前段染成强调色。离散取值时,在下方加刻度线:numberOfTickMarks 配 tickMarkPosition = .below,并用 allowsTickMarkValuesOnly = true 让滑钮吸附到刻度。设 isContinuous = true,让值在拖动过程中持续更新。

Debug prompt — when it misbehaves调试 Prompt —— 当它不听话时

Debug my macOS slider (NSSlider, SwiftUI Slider). Rule out: actions flooding on every pixel because isContinuous is on (or missing when live updates were wanted); allowsTickMarkValuesOnly snapping values you did not expect; a value binding writing back during drag and fighting the gesture; vertical orientation inferred from frame shape in AppKit, not set explicitly. The symptom:

调试我的 macOS 滑块(NSSlider、SwiftUI Slider)。逐项排除:isContinuous 开着,action 每像素狂发(或想要实时更新却没开);allowsTickMarkValuesOnly 把值吸附到意料之外的刻度;值绑定在拖拽中回写,和手势打架;AppKit 里方向是按 frame 形状推断的,没有显式设置。症状是:

In code代码里叫什么

Framework框架Symbol符号Note说明
AppKit NSSlider
SwiftUI Slider(value:in:step:)
AppKit NSSlider.numberOfTickMarks
AppKit NSSlider.allowsTickMarkValuesOnly snap to ticks吸附到刻度
AppKit NSSlider.tickMarkPosition .below / .above.below / .above
AppKit NSSlider.isContinuous act while dragging, not just on release拖动过程中就触发,而不是松手才触发

See also相关词条