I know should change the function drawTickMarks
,but what should I do to change tickmarks
color?
Asked
Active
Viewed 516 times
0

Txink
- 3
- 2
-
What have you tried so far. Show your code. – Warren Burton Jun 03 '18 at 08:33
-
I have subclass a NSSliderCell and override `- (void)drawBarInside:(NSRect)rect flipped:(BOOL)flipped`,and `drawTickMasks` is empty. – Txink Jun 03 '18 at 09:07
-
[link](https://i.stack.imgur.com/b9qR9.png) – Txink Jun 03 '18 at 09:15
-
Do you mean `drawTickMarks`? – Willeke Jun 03 '18 at 11:27
-
yes, I don't konw what I should write in `-(void)drawTickMarks` – Txink Jun 03 '18 at 11:47
1 Answers
1
If you want them in different color, draw them in a different color.
Having an empty implementation of drawTickMarks()
draws nothing.
Subclass NSSliderCell
and set the cell class.
Then provide a drawing routine in drawTickMarks()
class CustomSliderCell: NSSliderCell {
override func drawTickMarks() {
guard let slider = controlView as? NSSlider, slider.numberOfTickMarks > 0 else {
return
}
let tickWidth: CGFloat = 5
let horizontalinset: CGFloat = 5
let verticalinset: CGFloat = 1
let drawRect = slider.bounds.insetBy(dx: horizontalinset, dy: verticalinset) //squish in slightly
let step = drawRect.width/CGFloat(numberOfTickMarks-1) //classic fenceposts problem
var mark = CGFloat(0)
for _ in 0..<numberOfTickMarks {
let blob = NSBezierPath(roundedRect: NSRect(x: mark + horizontalinset , y:verticalinset, width: tickWidth, height: tickWidth*2), xRadius: tickWidth/2.0, yRadius: tickWidth/2.0)
NSColor.green.set()
blob.fill()
NSColor.darkGray.set()
blob.stroke()
mark += step
}
}
}
This one is a demo and far from perfect but should give you an ideas of what is needed.

Warren Burton
- 17,451
- 3
- 53
- 73