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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:10:33+00:00 2026-05-24T07:10:33+00:00

Dipping my feet into some more Core Graphics drawing, I’m attempting to recreate a

  • 0

Dipping my feet into some more Core Graphics drawing, I’m attempting to recreate a wicked looking metallic knob, and I’ve landed on what is probably a show-stopping issue.

There doesn’t seem to be any way to draw angle gradients in Core Graphics. I see there’s CGContextDrawRadialGradient() and CGContextDrawLinearGradient(), but there’s nothing that I see that would allow me to draw an angle gradient. Does anyone know of a workaround, or a bit of framework hidden away somewhere to accomplish this without pre-rendering the knob into an image file?

AngleGradientKnob http://dl.dropbox.com/u/3009808/AngleGradient.png.

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

    This is kind of thrown together, but it’s the approach I’d probably take. This is creating an angle gradient by drawing it directly into a bitmap using some simple trig, then clipping it to a circle. I create a grid of memory using a grayscale colorspace, calculate the angle from a given point to the center, and then color that based on a periodic function, running between 0 to 255. You could of course expand this to do RGBA color as well.

    Of course you’d cache this and play with the math to get the colors you want. This currently runs all the way from black to white, which doesn’t look as good as you’d like.

    - (void)drawRect:(CGRect)rect {
      CGImageAlphaInfo alphaInfo = kCGImageAlphaNone;
      CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
      size_t components = CGColorSpaceGetNumberOfComponents( colorSpace );
      size_t width = 100;
      size_t height = 100;
      size_t bitsPerComponent = 8;
      size_t bytesPerComponent = bitsPerComponent / 8;
      size_t bytesPerRow = width * bytesPerComponent * components;
      size_t dataLength = bytesPerRow * height;
    
      uint8_t data[dataLength];
    
      CGContextRef imageCtx = CGBitmapContextCreate( &data, width, height, bitsPerComponent,
                                          bytesPerRow, colorSpace, alphaInfo );
    
      NSUInteger offset = 0;
      for (NSUInteger y = 0; y < height; ++y) {
        for (NSUInteger x = 0; x < bytesPerRow; x += components) {
          CGFloat opposite = y - height/2.;
          CGFloat adjacent = x - width/2.;
          if (adjacent == 0) adjacent = 0.001;
          CGFloat angle = atan(opposite/adjacent);
          data[offset] = abs((cos(angle * 2) * 255));
          offset += components * bytesPerComponent;
        }
      }
    
      CGImageRef image = CGBitmapContextCreateImage(imageCtx);
    
      CGContextRelease(imageCtx);
      CGColorSpaceRelease(colorSpace);
    
      CGContextRef ctx = UIGraphicsGetCurrentContext();
    
      CGRect buttonRect = CGRectMake(100, 100, width, width);
      CGContextAddEllipseInRect(ctx, buttonRect);
      CGContextClip(ctx);
    
      CGContextDrawImage(ctx, buttonRect, image);
      CGImageRelease(image);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've done some work with Scriptaculous, and now I'm dipping my feet in to
I'm dipping my toes into Flash development and wondered how to post some variables
I'm dipping my feet into Windows Phone development and are starting to get to
I'm really just dipping my toes into the PHP and MySQL waters. I've made
I'm dipping my toes into Android development. I have a project that will interface
I am just dipping my hands into web technologies. I started with HTML and
I've been dipping into SitePoint book concerning CSS. The thing that struck me about
I am dipping my toes in more serious OOP (previously, just used inheritance) and
I'm dipping my toes into Python threading. I've created a supplier thread that returns
Dipping my toe into command prompts.. totally lost. I've installed Homebrew, and attempted to

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.