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

  • SEARCH
  • Home
  • 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 4627000
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:30:12+00:00 2026-05-22T03:30:12+00:00

I have a nsscroll view in my application and i made a subclass of

  • 0

I have a nsscroll view in my application and i made a subclass of nsscrollview to add a nsgradient but it doesn’t work this is my code in my implementation file:

#import "scrollview.h"
@implementation scrollview
@synthesize startingColor;
@synthesize endingColor;
@synthesize angle;

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
        [self setStartingColor:[NSColor colorWithCalibratedRed:0.941 green:0.941 blue:0.941 alpha:1]];
        [self setEndingColor:[NSColor colorWithCalibratedRed:0.6588 green:0.6588 blue:0.6588 alpha:1]];


        [self setAngle:90];
    }
    return self;
}

- (void)drawRect:(NSRect)rect {

    NSBezierPath* roundRectPath = [NSBezierPath bezierPathWithRoundedRect: [self bounds] xRadius:10 yRadius:10]; 
    [roundRectPath addClip];
    if (endingColor == nil || [startingColor isEqual:endingColor]) {
        // Fill view with a standard background color
        [startingColor set];
        NSRectFill(rect);
    }
    else {
        // Fill view with a top-down gradient
        // from startingColor to endingColor
        NSGradient* aGradient = [[NSGradient alloc]
                                 initWithStartingColor:startingColor
                                 endingColor:endingColor];
        [aGradient drawInRect:[self bounds] angle:angle];
    }
}
  • 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-22T03:30:13+00:00Added an answer on May 22, 2026 at 3:30 am

    The first step is to create a custom NSView subclass that draws a gradient:

    GradientBackgroundView.h:

    @interface GradientBackgroundView : NSView
    {}
    @end
    

    GradientBackgroundView.m:

    #import "GradientBackgroundView.h"
    @implementation GradientBackgroundView    
    - (void) drawRect:(NSRect)dirtyRect
    {
        NSGradient *gradient = [[[NSGradient alloc] initWithStartingColor:[NSColor redColor] endingColor:[NSColor greenColor]] autorelease];
        [gradient drawInRect:[self bounds] angle:90];
    }
    @end
    

    The next step is to make the scroll view’s document view an instance of this class (instead of plain NSView).

    In IB, double-click your scroll view, and in the Identity pane set the Class to GradientBackgroundView.

    From this point on, things are handled pretty much in the standard way. You can add subviews to the document view, resize it, etc. Here’s a screenshot:
    Gradient background

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

Sidebar

Related Questions

This is my application screenshot.There is only one NSScrollView on the window.I have made
Have converted devise new session from erb to Haml but doens't work, this is
i have an NSScrollView with an NSView set as its document view. I am
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have two instances of NSScrollView both presenting a view on the same content.
I currently have an NSTableView inside an NSScrollView and this gets it's contents from
I have an NSTableView embedded within a custom NSScrollView subclass, wherein I sometimes do
Have written all the code in a silverlight class library (dll) and linked this
I have an NSTextView inside an NSScrollView. The scroll view has the auto resize
I have a vertical NSSplitView containing on one of its sides a NSScrollView with

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.