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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:20:43+00:00 2026-05-14T02:20:43+00:00

i m the beginner in iphone. I want the divide the circle in equal

  • 0

i m the beginner in iphone. I want the divide the circle in equal parts. I have the code,

#import "MyView.h"
#define PI 3.14159265358979323846
static inline float radians(double degrees) { return degrees * PI / 180; }
@implementation MyView
- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
    }
    return self;
}
- (void)drawRect:(CGRect)rect {

    // circle
    CGContextRef contextRef = UIGraphicsGetCurrentContext();
    CGContextSetRGBFillColor(contextRef, 0, 0, 255, 0.1);
    CGContextSetRGBStrokeColor(contextRef, 0, 0, 255, 0.5);
    // Draw a circle (filled)
    //CGContextFillEllipseInRect(contextRef, CGRectMake(100, 100, 150, 150));
    // Draw a circle (border only)
    CGContextStrokeEllipseInRect(contextRef, CGRectMake(100, 100, 150, 150));
    //cgr


    CGContextRef  c5= UIGraphicsGetCurrentContext();
    //CGFloat red4[4] = {1.0f, 0.0f, 0.0f, 1.0f};
    CGContextSetLineWidth(c5, 2.0); 
    CGContextSetStrokeColorWithColor(c5, [UIColor brownColor].CGColor);
    CGContextBeginPath(c5);
    //CGContextMoveToPoint(c5, 101.0f, 156.0f);
    CGContextMoveToPoint(c5, 175.0f, 175.0f);
    CGContextAddLineToPoint(c5, 100.0f, 175.0f);
    CGContextStrokePath(c5);

    CGContextRef  c6= UIGraphicsGetCurrentContext();
    //CGFloat red4[4] = {1.0f, 0.0f, 0.0f, 1.0f};
    CGContextSetLineWidth(c6, 2.0); 
    CGContextSetStrokeColorWithColor(c6, [UIColor blueColor].CGColor);
    CGContextBeginPath(c6);
    CGContextMoveToPoint(c6, 175.0f, 175.0f);
    CGContextAddLineToPoint(c6, 175.0f, 250.0f);
    //CGContextAddLineToPoint(c6, 175.0f, 245.0f);
    CGContextStrokePath(c6);

    CGContextRef  c7= UIGraphicsGetCurrentContext();
    //CGFloat red4[4] = {1.0f, 0.0f, 0.0f, 1.0f};
    CGContextSetLineWidth(c7, 02.0); 
    CGContextSetStrokeColorWithColor(c7, [UIColor greenColor].CGColor);
    CGContextBeginPath(c7);
    CGContextMoveToPoint(c7, 175.0f, 175.0f);
    CGContextAddLineToPoint(c7, 175.0f, 100.0f);
    CGContextStrokePath(c7);

    CGContextRef  c8= UIGraphicsGetCurrentContext();
    //CGFloat red4[4] = {1.0f, 0.0f, 0.0f, 1.0f};
    CGContextSetLineWidth(c8, 2.0); 
    CGContextSetStrokeColorWithColor(c8, [UIColor redColor].CGColor);
    CGContextBeginPath(c8);
    //CGContextMoveToPoint(c5, 101.0f, 156.0f);
    CGContextMoveToPoint(c8, 175.0f, 175.0f);
    CGContextAddLineToPoint(c8, 250.0f, 175.0f);
    CGContextStrokePath(c8);

    CGContextRef  c9= UIGraphicsGetCurrentContext();
    //CGFloat red4[4] = {1.0f, 0.0f, 0.0f, 1.0f};
    CGContextSetLineWidth(c9, 2.0); 
    CGContextSetStrokeColorWithColor(c9, [UIColor purpleColor].CGColor);
    CGContextBeginPath(c9);
    //CGContextMoveToPoint(c5, 101.0f, 156.0f);
    CGContextMoveToPoint(c9, 175.0f, 175.0f);
    CGContextAddLineToPoint(c9, 230.0f, 125.0f);
    CGContextStrokePath(c9);

    CGContextRef  c10= UIGraphicsGetCurrentContext();
    //CGFloat red4[4] = {1.0f, 0.0f, 0.0f, 1.0f};
    CGContextSetLineWidth(c10, 2.0); 
    CGContextSetStrokeColorWithColor(c10, [UIColor orangeColor].CGColor);
    CGContextBeginPath(c10);
    //CGContextMoveToPoint(c5, 101.0f, 156.0f);
    CGContextMoveToPoint(c10, 175.0f, 175.0f);
    CGContextAddLineToPoint(c10, 120.0f, 125.0f);
    CGContextStrokePath(c10);

    CGContextRef  c11= UIGraphicsGetCurrentContext();
    //CGFloat red4[4] = {1.0f, 0.0f, 0.0f, 1.0f};
    CGContextSetLineWidth(c11, 2.0); 
    CGContextSetStrokeColorWithColor(c11, [UIColor magentaColor].CGColor);
    CGContextBeginPath(c11);
    //CGContextMoveToPoint(c5, 101.0f, 156.0f);
    CGContextMoveToPoint(c11, 175.0f, 175.0f);
    CGContextAddLineToPoint(c11, 120.0f, 225.0f);
    CGContextStrokePath(c11);

    CGContextRef  c12= UIGraphicsGetCurrentContext();
    //CGFloat red4[4] = {1.0f, 0.0f, 0.0f, 1.0f};
    CGContextSetLineWidth(c12, 2.0); 
    CGContextSetStrokeColorWithColor(c12, [UIColor yellowColor].CGColor);
    CGContextBeginPath(c12);
    //CGContextMoveToPoint(c5, 101.0f, 156.0f);
    CGContextMoveToPoint(c12, 175.0f, 175.0f);
    CGContextAddLineToPoint(c12, 231.0f, 226.0f);
    CGContextStrokePath(c12);


}

- (void)makeCircleAt:(CGPoint)center withDiameter:(float)diameter withColor:(int)myColor
{
    float radius = diameter * 0.5;
    CGRect myOval = {center.x - radius, center.y - radius, diameter, diameter};
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
    CGContextAddEllipseInRect(context, myOval);
    CGContextFillPath(context);
}

- (void)dealloc {
    [super dealloc];
}
@end
.

I want the above code divide the circle dynamically with out using c5,c6……c12 block, simply i want to using a loop in which i entering the number and dividing the circle on the basis of number.

  • 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-14T02:20:43+00:00Added an answer on May 14, 2026 at 2:20 am

    You probably want to divide the circle up into a series of arcs and draw wedges.

    Get the start and end points of the arcs along the circumference of the circle suing (x – h)^2 + (y – k)^2 = r^2. Then draw three lines: One each the start and end points from the center and then one arc segment from he start point to end point. (Use CGContextAddArc). Then fill in the path.

    Once you have the points along the perimeter in an array, you can loop through them using the same loop for any arbitrary division.

    Edit:

    Here is an old cocoa example that shows the math involved.

    Here’s an iPhone pie chart example.

    This thread has more links.

    I think if you google “iPhone and Pie Chart” you should hit numerous examples for solving the same basic problem.

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

Sidebar

Related Questions

i m the beginner in iphone programming i want to make an application which
hiiiii, i am a beginner for iphone and i want to make so much
I'm a beginner iPhone developer. My code is the following: UIBarButtonItem *fixedSpace = [[UIBarButtonItem
I am a iPhone beginner and i want to know how many parameters the
I m the beginner in iphone Thanks for sending me answer.... I want to
I m the beginner in iphone software development. I want to make my own
I'm beginner with iPhone and want to know how to add a view in
I'm the beginner in iPhone software development, and I'm creating a HTTP request using
I m the beginner in iphone software development. I developing the application on skin
I am the beginner in iphone development. I develop an application in which i

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.