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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:41:23+00:00 2026-05-23T10:41:23+00:00

I have the following UIView custom class: @implementation BackgroundView – (void)drawRect:(CGRect)rect { CGContextRef currentContext

  • 0

I have the following UIView custom class:

@implementation BackgroundView

- (void)drawRect:(CGRect)rect 
{

    CGContextRef currentContext = UIGraphicsGetCurrentContext();

    CGGradientRef glossGradient;
    CGColorSpaceRef rgbColorspace;
    size_t num_locations = 2;
    CGFloat locations[2] = { 0.0, 1.0 };

    float r = (255.0)/(255.0);
    float g = (165.0)/(255.0);
    float b = (0.0)/(255.0);

    float rr = (238.0)/(255.0);
    float gg = (118.0)/(255.0);
    float bb = (0.0)/(255.0);

    CGFloat components[8] = { r, g, b, 1.0,  // Start color
        rr, gg, bb, 1.0 }; // End color

    rgbColorspace = CGColorSpaceCreateDeviceRGB();
    glossGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);

    CGRect currentBounds = self.bounds;
    CGPoint topCenter = CGPointMake(CGRectGetMidX(currentBounds), 0.0f);
    CGPoint midCenter = CGPointMake(CGRectGetMidX(currentBounds), CGRectGetMidY(currentBounds));
    CGContextDrawLinearGradient(currentContext, glossGradient, topCenter, midCenter, 0);

    CGGradientRelease(glossGradient);
    CGColorSpaceRelease(rgbColorspace); 
}


@end

Basically, it’s supposed to make an orange gradient. The values “r”, “g”, and “b” are for a light orange, and the values “rr”, “gg”, “bb” are for a dark orange. But it doesn’t work. Only the top of the frame is orange, and the bottom of the frame is black. I can’t seem to get rid of the black.

What values would I use for an orange nice gradient. Can someone please look for mistakes? I can’t find any. Thanks so much!

  • 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-23T10:41:24+00:00Added an answer on May 23, 2026 at 10:41 am

    That’s because you specify that the end point for your gradient is in middle of the currentBounds – see this line:

    CGPoint midCenter = CGPointMake(CGRectGetMidX(currentBounds), CGRectGetMidY(currentBounds));
    

    To get rid of the black make sure the y coordinate is at the bottom of your view.

    Alternatively, you could use this code to extend your gradient after the end point

     CGContextDrawLinearGradient(currentContext, glossGradient, topCenter, midCenter, kCGGradientDrawsAfterEndLocation);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following classes. class A { public: void fun(); } class B: public
I'm developing an iPhone app. I have the following class: #import Triangulo.h @implementation Triangulo
I have the following code: [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationCurveEaseOut | UIViewAnimationOptionAllowUserInteraction animations:^{ CGRect r
I have the following core animation code in my app : -(void)startCoreAnimation [UIView beginAnimations:@IconFade
I have a custom UIView which is composed of many images, their positions are
I have a the following piece of code: -(IBAction)routePicker { UIView *myView = [[UIView
if I have the following view hierarchy UIView --- top level view --UIButton --UIView
I have a custom UIViewController inited from a nib file with the following view
I have created the following subclass to do some custom drawing: // DocumentIconView.h @interface
I have the following code in two different classes (both subclasses of UIView). In

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.