Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4576362
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:11:41+00:00 2026-05-21T20:11:41+00:00

How to create custom NSSlider that is working exactly as slider in System Preferences

  • 0

How to create custom NSSlider that is working exactly as slider in System Preferences -> Desktop & Screen Saver -> Screen Saver -> Start screen saver: ?

I tried to subclass NSSliderCell with overridden continueTracking: but it don’t work as expected.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T20:11:42+00:00Added an answer on May 21, 2026 at 8:11 pm

    I played around for a bit and at least got off to a pretty good start with an NSSliderCell subclass.

    MDSliderCell.h:

    #import <Cocoa/Cocoa.h>
    
    @interface MDSliderCell : NSSliderCell {
        BOOL    tracking;
    }
    
    @end
    

    MDSliderCell.m:

    #import "MDSliderCell.h"
    
    @implementation MDSliderCell
    
    - (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView {
        if ([self numberOfTickMarks] > 0) tracking = YES;
        return [super startTrackingAt:startPoint inView:controlView];
    }
    
    #define MD_SNAPPING 10.0
    
    - (BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint 
       inView:(NSView *)controlView {
       if (tracking) {
          NSUInteger count = [self numberOfTickMarks];
          for (NSUInteger i = 0; i < count; i++) {
              NSRect tickMarkRect = [self rectOfTickMarkAtIndex:i];
              if (ABS(tickMarkRect.origin.x - currentPoint.x) <= MD_SNAPPING) {
                 [self setAllowsTickMarkValuesOnly:YES];
              } else if (ABS(tickMarkRect.origin.x - currentPoint.x) >= MD_SNAPPING &&
                 ABS(tickMarkRect.origin.x - currentPoint.x) <= MD_SNAPPING *2) {
                 [self setAllowsTickMarkValuesOnly:NO];
              }
          }
       }
      return [super continueTracking:lastPoint at:currentPoint inView:controlView];
    }
    
    - (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint
           inView:(NSView *)controlView mouseIsUp:(BOOL)flag {
        [super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag];
    }
    
    @end
    

    Basically, during the -continueTracking:at:inView:, it checks to see how close it is to a tick mark, and if it’s close enough, it turns on the option to only allow tick mark values. That causes it to snap to the tick mark, then once you get far enough away, you turn the “tick mark-only” option off until you get close enough to another tick mark.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create custom bullet points and it is not working. This
I'm trying to create custom icons for my taskbar/desktop icons in my Flex WindowedApplication.
I'm trying to create custom events in JQuery that are supposed to detect when
I'm trying to create custom view that shows some info about it: Name, Id,
I want to create custom WPF control that has a single child control inside.
I'm trying to create custom layout for android. It normally draws on screen, but
Am using .htaccess to create custom error pages, but the thing is that, it
I'm trying to create custom view that draws image downloaded from Url. The code
I want to create custom control (let's name it DesignPanel ) that will allow
How to create Custom shaped buttons in c#: say triangular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.