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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:21:11+00:00 2026-05-23T16:21:11+00:00

So far I have looked at using CGContextDrawLinearGradient() and CGContextDrawRadialGradient(), however, with the former

  • 0

So far I have looked at using CGContextDrawLinearGradient() and CGContextDrawRadialGradient(), however, with the former I can’t figure out how to make the gradient look like a sphere, and with the latter, I can’t figure out how to make the gradient into the shape of a sphere, because every time I try, it turns out in the shape of the full cylinder instead of only a sphere.

The code I am using to current draw a 2D circle is shown below. I would like to use a gradient or any other method possible using only Core Graphics and/or Quartz 2D to fill the circle in a manner that makes it look like a sphere.

Current code for drawing a circle:

CGContextRef ctx = UIGraphicsGetCurrentContext();
float x = 20.0;
float y = 20.0;
float radius = 12.5;
CGContextFillEllipseInRect(ctx, CGRectMake(x, y, radius, radius);

P.S. – The above code works just as its supposed to, so in case there are any errors, they’re just from my errors while typing the question, not while typing code into the actual file.

  • 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-23T16:21:12+00:00Added an answer on May 23, 2026 at 4:21 pm

    I believe this is the effect you are looking for:

    enter image description here

    This is created using a radial gradient. The gradient starts with a radius of 0 and ends with a radius of the size of the circle. The center point of the start must be within the circle created by the end, or you will get a cone shape instead. Here is the code I used to make this image (a couple parts need to be translated to iOS before you use it):

    CGContextRef ctxt = [[NSGraphicsContext currentContext] graphicsPort];
    CGGradientRef gradient;
    CGColorSpaceRef colorSpace;
    CGFloat locations[] = {0.0,1.0};
    CGFloat components[] = { 0.5,1.0,1.0,1.0, 0.25,0.5,0.5,1.0 };
    colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
    gradient = CGGradientCreateWithColorComponents(colorSpace,components,locations,
                                                   sizeof(locations)/sizeof(CGFloat));
    CGPoint start = {70.0,130.0}, end = {100.0,100.0};
    CGFloat startRadius = 0.0, endRadius = 90.0;
    CGContextDrawRadialGradient(ctxt,gradient,start,startRadius,end,endRadius,0);
    CGGradientRelease(gradient);
    CGColorSpaceRelease(colorSpace);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks to everyone out there helping newbies like me. So far I have this:
So far I have learned about generating thread dump and heap dump using jstack
I am investigating creating cross platform mobile apps using PhoneGap. I have looked at
I have looked at the following question: Could someone provide a C# example using
Sorry if this has been asked elsewhere. I have looked but can't find any
Now that Rails 3 beta is out, I thought I'd have a look at
I have looked around the WordPress plugin site for some time and so far,
I have a query like: var function = GetSomeExpression(); using (FooModel context = new
So far I have encountered adjacency list, nested sets and nested intervals as models
So far i have got the code below which works lovely when trying an

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.