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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:21:47+00:00 2026-05-21T21:21:47+00:00

Hi I have a simple application where I have a some custom views and

  • 0

Hi
I have a simple application where I have a some custom views and I want to add a gradient effect in some of them with CAgradientlayer but my code doesn’t work well, my code

gradientLayer.bounds = CGRectMake(0, 0, [customer_general_view bounds].size.width, [customer_general_view bounds].size.height);

CGColorRef color1 = CGColorCreateGenericRGB(0.98, 0.98, 0.98, 1);
CGColorRef color2 = CGColorCreateGenericRGB(1, 1, 1, 1);
NSNumber *stopOne     = [NSNumber numberWithFloat:0.00];
NSNumber *stopTwo     = [NSNumber numberWithFloat:0.02];
NSNumber *stopThree  = [NSNumber numberWithFloat:0.02];
NSNumber *stopFour    = [NSNumber numberWithFloat:0.50];
NSNumber *stopFive     = [NSNumber numberWithFloat:0.50];
NSNumber *stopSix       = [NSNumber numberWithFloat:0.95];
NSNumber *stopSeven  = [NSNumber numberWithFloat:1.00];
NSArray *locations = [NSArray arrayWithObjects:stopOne, stopTwo, stopThree, stopFour, stopFive, stopSix, stopSeven, nil];


//Package the new color pair in an array (the format required for CAGradientLayer)
NSArray *colors = [NSArray arrayWithObjects:(id) color1, color2, nil];

[gradientLayer setColors:colors];
gradientLayer.locations = locations;


//Release the colors
CGColorRelease(color1);
CGColorRelease(color2);

[customer_general_view setLayer:gradientLayer];
[customer_general_view setWantsLayer:YES];

I don’t know if i’m missing something.

  • 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-21T21:21:48+00:00Added an answer on May 21, 2026 at 9:21 pm

    I solve my problem making a subclass of NSView. In the header I wrote:

    @interface test_gradient : NSView {
        NSColor *startingColor;
        NSColor *endingColor;
        int angle;
    }
    @property(nonatomic, retain) NSColor *startingColor;
    @property(nonatomic, retain) NSColor *endingColor;
    @property(assign) int angle;
    
    @end
    

    And in the implementation I wrote:

    @implementation test_gradient
    
    @synthesize startingColor;
    @synthesize endingColor;
    @synthesize angle;
    
    - (id)initWithFrame:(NSRect)frame {
        self = [super initWithFrame:frame];
        if (self) {
            // Initialization code here.
            [self setEndingColor:[NSColor colorWithCalibratedRed:0.941 green:0.941 blue:0.941 alpha:1]];
            [self setStartingColor:[NSColor colorWithCalibratedRed:0.701 green:0.701 blue:0.701 alpha:1]];
    
    
            [self setAngle:150];
        }
        return self;
    }
    
    - (void)drawRect:(NSRect)rect {
        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];
        }
    }
    
    @end
    

    But I couldn’t solve the problem with the CAgradient layer if anyone has a answer for that it would be great

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

Sidebar

Related Questions

I have an application that uses simple sockets to pass some characters between two
I have a simple application with the following code: FileInfo[] files = (new DirectoryInfo(initialDirectory)).GetFiles();
I have a simple WPF application with a menu. I need to add menu
Early, I have defined custom section in Console application and it works fine. But
I have a simple application using netbeans for developing and maven for building et
I have a simple WPF application which I am trying to start. I am
I have a simple j2ee application: foo.ear - foo.war - foo.jar (ejb3 jar) I
I have a very simple WPF application in which I am using data binding
I have an idea for a simple application which will monitor a group of
Hi I am developing a simple application based upon ASP.NET MVC. I have altered

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.