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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:29:06+00:00 2026-06-09T14:29:06+00:00

I like to draw a glass with a few Elements – Top Ellipse –

  • 0

I like to draw a glass with a few Elements
– Top Ellipse
– Bottom Ellipse
– and the Lines Inbetween

Next, it should be filled with a Gradient. The Elements work, but at the point, where the middle of the glass comes in touch with the top or bottom ellipse the area get’s clipped.

- (void)drawRect:(CGRect)rect
{
    CGPoint c = self.center;    
    // Drawing code
    CGContextRef cx = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(cx, 1.0);
    [[UIColor whiteColor] setStroke];

    //  DrawTheShapeOfTheGlass
    CGContextBeginPath(cx);
    //  Top and Bottom Ellipse
    CGContextAddEllipseInRect(cx, CGRectMake(0, 0, 100, 20));
    CGContextAddEllipseInRect(cx, CGRectMake(10, 90, 80, 20));
    //  Define the points for the Area inbetween
    CGPoint points[] = { {0.0,10.0},{10.0,100.0},{90.0,100.0},{100.0,10.0} };
    CGContextAddLines(cx, points, 4);
    CGContextClosePath(cx);
    //  Clip, that's only the Clipped-Area wil be filled with the Gradient
    CGContextClip(cx);

    //  CreateAndDraw the Gradient
    CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
    CGFloat colorSpace[] = {1.0f, 1.0f, 1.0f, 0.0f,
                        0.0f, 0.0f, 1.0f, 1.0f };
    CGFloat locations[] = { 0.0, 1.0 };

    CGGradientRef myGradient = CGGradientCreateWithColorComponents(rgbColorSpace, colorSpace, locations, 2);

    CGPoint s = CGPointMake(0, 0);
    CGPoint e = CGPointMake(100, 100);
    CGContextDrawLinearGradient(cx, myGradient, s, e, kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);

    CGColorSpaceRelease(rgbColorSpace);
    CGGradientRelease(myGradient);
}

Here how it looks like:

enter image description here

Is there any possibility to “fill” the whole ellipse? I played around with BlendModes but it didn’t help.

Thanks

  • 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-09T14:29:08+00:00Added an answer on June 9, 2026 at 2:29 pm

    Try replacing the points[] initialization code with the following…

    CGPoint points[] = {{0.0,10.0},{100.0,10.0},{90.0,100.0},{10.0,100.0}};
    

    CoreGraphics uses the non-zero winding count rule to determine how to fill a path. Since ellipses are drawn clockwise and your trapezoid was drawn counter clockwise, the overlapping regions were not filled. Changing the drawing order of the trapezoid to clockwise will result in an object that is completely filled.

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

Sidebar

Related Questions

I'd like to draw the lines of a simple ruler with Quartz2D, just for
I'd like to draw lines on an image. Basically allow the user to draw
I would like to draw some simple drawings (lines, circles, etc.) on panel in
I would like to draw lines (of arbitrary position and length) onto a surface
I would like to draw some lines using Path. It always show me error
I'd like to draw a white filled polygon, with arbitrary angle, in a black
I like to draw a line, but cocos2d inside ccDrawLine serrate, how to draw
I'd like to draw text on some location on the screen without using UILabel
I'd like to draw some statistics charts using QT4.7 , here are some examples:
I'd like to draw a mesh with a big mesh (think ~120k vertices). If

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.