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 7050769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:11:04+00:00 2026-05-28T03:11:04+00:00

I am trying to implement a custom circular slider which uses images to draw

  • 0

I am trying to implement a custom circular slider which uses images to draw the dial and the knob. For this purpose I have subclassed NSSliderCell and overridden the drawBarInside and drawKnob methods.
Now, if I leave the slider type as default (horizontal), my drawing functions are called and images are drawn in stead of the default bar and knob (of course it looks all wrong since images are made for a circular slider, but they are there). But as soon as I change the slider type to circular (either in IB or by setting self.sliderType = NSCircularSlider; in my slider cell) those two methods are never called and my images are not drawn (only the standard dial is created).
Am I forgetting something here, or can circular sliders not be customized at all?

Here is my code:
DialSliderCell is a subclass of NSSliderCell and is initiated and set in a class called DialSlider which is a subclass of NSSlider (this class does nothing else at the time).

@implementation DialSliderCell

- (id)init {
    self = [super init];
    if (self) {
        dialImage = [NSImage imageNamed:@"dial"];
        knobImage = [NSImage imageNamed:@"dialKnob"];
        self.sliderType = NSCircularSlider;
    }
    NSLog(@"init");
    return self;
}

- (void)drawKnob:(NSRect)knobRect {
    knobRect.size = knobImage.size;
    [knobImage drawInRect:knobRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
    NSLog(@"drawKnob");
}

- (void)drawBarInside:(NSRect)aRect flipped:(BOOL)flipped {
    [dialImage drawInRect:aRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
    NSLog(@"drawBarInside");
}

@end
  • 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-28T03:11:05+00:00Added an answer on May 28, 2026 at 3:11 am

    I have solved this problem by overriding the drawInteriorWithFrame method. The solution is based on the original method. I just removed anything not related to circular sliders, removed the original graphics and added my own. The geometry is almost entirely original.

    - (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
    {
        cellFrame = [self drawingRectForBounds: cellFrame];
        _trackRect = cellFrame;
    
        NSPoint knobCenter;
        NSPoint point;
        float fraction, angle, radius;
    
        knobCenter = NSMakePoint(NSMidX(cellFrame), NSMidY(cellFrame));
    
        [dialImage drawInRect:cellFrame fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
    
        int knobDiameter = knobImage.size.width;
        int knobRadius = knobDiameter / 2;
        fraction = ([self floatValue] - [self minValue]) / ([self maxValue] - [self minValue]);
        angle = (fraction * (2.0 * M_PI)) - (M_PI / 2.0);
        radius = (cellFrame.size.height / 2) - knobDiameter;
        point = NSMakePoint((radius * cos(angle)) + knobCenter.x,
                        (radius * sin(angle)) + knobCenter.y);
    
        NSRect dotRect;
        dotRect.origin.x = point.x - knobRadius;
        dotRect.origin.y = point.y - knobRadius;
        dotRect.size = knobImage.size;
        [knobImage drawInRect:dotRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
    }
    

    The size of the cellFramerectangle is set to the size of the dialImageimage.

    Notice that the method above doesn’t seem to get called automatically so I also had to override the drawWithFrame method and make it call drawInteriorWithFrame:

    - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
    {
        [self drawInteriorWithFrame:cellFrame inView:controlView];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a custom validation annotation in Seam. We have a list
I'm trying to implement the Media Player custom field control described in this MSDN
I'm trying to implement a custom menu in my joomla template. I added this
I have a listing of custom post types and I'm trying to implement a
I am trying to implement a custom menu for Internet Explorer 7.0. For this
I am trying to implement a custom Java widget using GWT.This requires me to
I am trying to implement a custom Java widget using GWT.This requires me to
I'm trying to implement a custom SessionIDManager very similar this example . I'm putting
I am trying to implement a custom UIView which is basically a pie menu
I'm trying to implement a custom TableRenderer as described in this tutorial . I'd

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.