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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:28:13+00:00 2026-05-13T22:28:13+00:00

Whats wrong with this code? -(void) drawRect:(CGRect) rect { CGContextRef c = UIGraphicsGetCurrentContext(); if

  • 0

Whats wrong with this code?

-(void) drawRect:(CGRect) rect {
        CGContextRef c = UIGraphicsGetCurrentContext();
        if (c != nil)  {
            CGContextSetFillColorWithColor(c, self.cornerColor.CGColor);
            [self drawRoundedCornersInRect:self.bounds inContext:c];
            CGContextFillPath(c);
        }
    }

    -(void) drawCornerInContext:(CGContextRef)c cornerX:(int) x cornerY:(int) y
            arcEndX:(int) endX arcEndY:(int) endY {
        CGContextMoveToPoint(c, x, endY);
        CGContextAddArcToPoint(c, x, y, endX, y, radius);
        CGContextAddLineToPoint(c, x, y);
        CGContextAddLineToPoint(c, x, endY);
    }

    -(void) drawRoundedCornersInRect:(CGRect) rect inContext:(CGContextRef) c  {
     int x_left = rect.origin.x;
     int x_left_center = rect.origin.x + radius;
     int x_right_center = rect.origin.x + rect.size.width - radius;
     int x_right = rect.origin.x + rect.size.width;
     int y_top = rect.origin.y;
     int y_top_center = rect.origin.y + radius;
     int y_bottom_center = rect.origin.y + rect.size.height - radius;
     int y_bottom = rect.origin.y + rect.size.height;

        if (roundUpperLeft) {
            [self drawCornerInContext:c cornerX: x_left cornerY: y_top
                  arcEndX: x_left_center arcEndY: y_top_center];
        }

        if (roundUpperRight) {
            [self drawCornerInContext:c cornerX: x_right cornerY: y_top
                  arcEndX: x_right_center arcEndY: y_top_center];
        }

        if (roundLowerRight) {
            [self drawCornerInContext:c cornerX: x_right cornerY: y_bottom
                  arcEndX: x_right_center arcEndY: y_bottom_center];
        }

        if (roundLowerLeft) {
            [self drawCornerInContext:c cornerX: x_left cornerY: y_bottom
                  arcEndX: x_left_center arcEndY: y_bottom_center];
        }
    }

No errors, No warnings … but the round corners don’t work at all. I found this code here.

  • 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-13T22:28:14+00:00Added an answer on May 13, 2026 at 10:28 pm

    You need to begin a path, and close it when you’re done. Your 2nd call to CGContextAddLineToPoint messes things up I think. Here’s a snippet that works. Study it and enhance it to support your multiple cases (it seems that you want to be able to round only some corners, and not necessarily all of them…)

    void addRoundedRect(CGContextRef ctx, CGRect rect, float cornerRadius) {
        if (cornerRadius <= 2.0) {
            CGContextAddRect(ctx, rect);
        } else {
            float x_left = rect.origin.x;
            float x_left_center = x_left + cornerRadius;
            float x_right_center = x_left + rect.size.width - cornerRadius;
            float x_right = x_left + rect.size.width;
            float y_top = rect.origin.y;
            float y_top_center = y_top + cornerRadius;
            float y_bottom_center = y_top + rect.size.height - cornerRadius;
            float y_bottom = y_top + rect.size.height;
            /* Begin path */
            CGContextBeginPath(ctx);
            CGContextMoveToPoint(ctx, x_left, y_top_center);
            /* First corner */
            CGContextAddArcToPoint(ctx, x_left, y_top, x_left_center, y_top, cornerRadius);
            CGContextAddLineToPoint(ctx, x_right_center, y_top);
            /* Second corner */
            CGContextAddArcToPoint(ctx, x_right, y_top, x_right, y_top_center, cornerRadius);
            CGContextAddLineToPoint(ctx, x_right, y_bottom_center);
            /* Third corner */
            CGContextAddArcToPoint(ctx, x_right, y_bottom, x_right_center, y_bottom, cornerRadius);
            CGContextAddLineToPoint(ctx, x_left_center, y_bottom);
            /* Fourth corner */
            CGContextAddArcToPoint(ctx, x_left, y_bottom, x_left, y_bottom_center, cornerRadius);
            CGContextAddLineToPoint(ctx, x_left, y_top_center);
            /* Done */
            CGContextClosePath(ctx);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 441k
  • Answers 441k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The problem arose because somewhere deep in the code of… May 15, 2026 at 5:27 pm
  • Editorial Team
    Editorial Team added an answer It is not supported. Here is a note from Apple… May 15, 2026 at 5:27 pm
  • Editorial Team
    Editorial Team added an answer declare @path varchar(255), @mydb varchar(50) SELECT @mydb = 'MyDBToBackUp' select… May 15, 2026 at 5:27 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.