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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:07:28+00:00 2026-05-26T00:07:28+00:00

So in my custom view, I’m trying to draw a white/gray gradient using Core

  • 0

So in my custom view, I’m trying to draw a white/gray gradient using Core Graphics. I have the following code:

UIColor *color1 = [UIColor whiteColor];
UIColor *color2 = [UIColor colorWithRed:209.0/255.0 green:212.0/255.0 blue:217.0/255.0 alpha:1.0];

CFMutableArrayRef colors = CFArrayCreateMutable(NULL, 0, NULL);
CFArrayAppendValue(colors, color1.CGColor);
CFArrayAppendValue(colors, color2.CGColor);

CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGFloat locations[2] = {0.0, 1.0};
CGGradientRef gradient = CGGradientCreateWithColors(colorspace, colors, locations);

CGContextDrawLinearGradient(UIGraphicsGetCurrentContext(), gradient, topCenter, bottomCenter, kCGGradientDrawsAfterEndLocation);

I think this code is fairly straightforward and should result in a nice white/gray gradient. But it doesn’t; it draws a transparent/gray gradient.

I think it may have something to do with the view’s background color, which is [UIColor clearColor]. But I cannot change that, as I need to have some portions of my view to be transparent.

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-05-26T00:07:29+00:00Added an answer on May 26, 2026 at 12:07 am
    UIColor *color1 = [UIColor whiteColor];
    

    The above line likely creates a color in the greyscale colorspace.

    Try this instead:

    UIColor *color1 = [UIColor colorWithRed:1.f green:1.f blue:1.f alpha:1.f];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a custom view whose color is set using the following, canvas.drawColor(Color.RED);
I have a custom view that draws an CGImage using: - (void) drawImage {
I have a custom View which I draw on bitmaps in the onDraw function.
I have a custom view that I am trying to display, however I am
So I have a custom view set up in code (no XML layout defined
I created a custom View and am trying to draw an array of ints
I have a custom view with that code : - (void)drawRect:(CGRect)rect { UIImage* theImage
I have a custom view engine in ASP.NET MVC and since upgrading to RC1
I've created a custom view class and right now just want to draw an
I have a simple custom view that is connected via outlet to a NIB.

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.