Is there a way to hide the tick marks of NSSlider
?
Asked
Active
Viewed 1,480 times
2

Paulo Mattos
- 18,845
- 10
- 77
- 85

user635064
- 6,219
- 12
- 54
- 100
-
Do you want to do this in Interface Builder or through code? – Apr 22 '11 at 14:06
-
Hi, thanks for the reply. It doesn't matter. – user635064 Apr 22 '11 at 16:34
3 Answers
8
If you want to keep the tickmark stopping behaviour but hide them, you can override the NSSliderCell's
-(NSRect)rectOfTickMarkAtIndex:(NSInteger)index
and provide a rectangle with 0 dimensions.

Tristan Warner-Smith
- 9,631
- 6
- 46
- 75
-
up for this most correct way! -(NSRect)rectOfTickMarkAtIndex:(NSInteger)index { return NSZeroRect; } – Jiulong Zhao May 22 '13 at 22:56
2
You can use the -[NSSlider setNumberOfTickMarks:]
method to set the number of tick marks to zero. This will hide them.
In Interface Builder you can just set this to zero in the inspector panel.
-
1Yes, but then it won't stop at Integers values. I am using tick marks so the user can only stop at say 5 rather than 5.5. But if I remove the tick marks, then the slider can stop anywhere. Thanks for the input though. – user635064 Apr 22 '11 at 16:33
-
1@user: Just set up a `NSNumberFormatter` that only outputs integer values. :) – sudo rm -rf May 07 '11 at 04:32
0
You can override [NSSliderCell drawTickMarks]
and do nothing in your implementation.
Make sure to set your subclass as the NSSlider's cell.

Yoav
- 5,962
- 5
- 39
- 61
-
That used to work, but stopped working for us in 10.14. Overriding rectOfTickMarkAtIndex still works. – Avitzur Oct 12 '18 at 23:13