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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:30:10+00:00 2026-06-01T14:30:10+00:00

I am drawing on a custom view an NSGradient like this: – (void)drawRect: (NSRect)dirtyRect

  • 0

I am drawing on a custom view an NSGradient like this:

- (void)drawRect: (NSRect)dirtyRect
{
    NSGradient* g = [[NSGradient alloc] initWithStartingColor: _color endingColor: [NSColor clearColor]];   
    [g drawInRect: [self bounds] angle: 90];
}

If _color is a normal color, for example [NSColor blueColor], everything is fine. The problem is that _color comes from a pattern image (which in this case is mostly grey with some fancy pixels on it), and when that happens the program keeps logging this error:

*** -[NSGradient initWithColors:atLocations:colorSpace:]: the color NSPatternColorSpace CGImageSource=0x400367d60″
)> cannot be converted into color space Generic RGB colorspace

_color = [NSColor colorWithPatternImage: [NSImage imageNamed: @"mainBG.png"]]

The image is completely opaque and is a png file.
Any ideas? perhaps I should change the file type? I don’t know…

EDIT:

If I define _color like this:

_color = [[NSColor colorWithPatternImage: [NSImage imageNamed: @"mainBG.tiff"]] colorUsingColorSpace: [NSColorSpace genericRGBColorSpace]]

then no gradient is displayed. Nothing. Just as if I didn’t have the drawRect: method. Any ideas?

  • 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-06-01T14:30:11+00:00Added an answer on June 1, 2026 at 2:30 pm

    An NSGradient doesn’t work with a pattern as one of the colors. That’s what the exception is telling you. It will only work with an NSColor that can be converted to an RGB color. If you want to make your pattern fade to clear, you’ll have to do it another way.

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

Sidebar

Related Questions

I have a view that I want to add some custom drawing to. I
I have a JPanel that implements custom drawing to draw a background. Over this,
I have a custom view with some drawing on it. I want to resize
I am drawing a custom view in my application which basically takes arguments(XML) as
I have created a custom view and drawing a bitmap image. How can i
I have seen that in Cocoa I can create a custom view using drawing
I my outline view, i am adding Custom cell, To drawing custom cell, i
i'm following the suggestion in this post: Drawing a gameboard like checkers in Android
I'm playing around with 2D drawing within a custom view. So far I've got
I have a drawing activity that creates a custom 'canvas' View that occupies the

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.