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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:09:42+00:00 2026-06-05T04:09:42+00:00

At first I draw graphics: -(void)drawRect: (CGRect)rect{ //Circle circle = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(circle, [UIColor darkGrayColor].CGColor);

  • 0

At first I draw graphics:

    -(void)drawRect: (CGRect)rect{  

        //Circle
    circle = UIGraphicsGetCurrentContext();  
    CGContextSetFillColorWithColor(circle, [UIColor darkGrayColor].CGColor);
    CGContextFillRect(circle,CGRectMake(10,10, 50, 50));

        //rectangle
    rectangle = UIGraphicsGetCurrentContext();  
    CGContextSetFillColorWithColor(rectangle, [UIColor darkGrayColor].CGColor);
    CGContextFillRect(rectangle, CGRectMake(10, 10, 50, 50));

        //square 
    square = UIGraphicsGetCurrentContext();  
    CGContextSetFillColorWithColor(square, [UIColor darkGrayColor].CGColor);
    CGContextFillRect(square, CGRectMake(100, 100, 25, 25));

        //triangle  
    triangle = UIGraphicsGetCurrentContext(); 
    CGContextSetFillColorWithColor(triangle, [UIColor darkGrayColor].CGColor);
    CGPoint points[6] = { CGPointMake(100, 200), CGPointMake(150, 250),
                              CGPointMake(150, 250), CGPointMake(50, 250),
                              CGPointMake(50, 250), CGPointMake(100, 200) };
    CGContextStrokeLineSegments(triangle, points, 6);

    }

And now I want to put the graphics into an Array:

-(void)viewDidLoad {

grafics = [[NSMutableArray alloc]initWithObjects: circle,rectangle,square,triangle];
[self.navigationItem.title = @"Shape"];
[super viewDidLoad];
}

The problem is, that I have to make a cast thereby the objects fit into this array. Another problem is that the UITableViewController does not load the array into the rows. There is nothing wrong with the tableview, but a failure with handling CGContext. What I am doing wrong?

  • 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-05T04:09:44+00:00Added an answer on June 5, 2026 at 4:09 am

    drawRect: is a method on UIView used to draw the view itself, not to pre-create graphic objects.

    Since it seems that you want to create shapes to store them and draw later, it appears reasonable to create the shapes as UIImage and draw them using UIImageView. UIImage can be stored directly in an NSArray.

    To create the images, do the following (on the main queue; not in drawRect:):

    1) create a bitmap context

    UIGraphicsBeginImageContextWithOptions(size, opaque, scale);
    

    2) get the context

    CGContextRef context = UIGraphicsGetCurrentContext();
    

    3) draw whatever you need

    4) export the context into an image

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    

    5) destroy the context

    UIGraphicsEndImageContext();
    

    6) store the reference to the image

    [yourArray addObject:image];
    

    Repeat for each shape you want to create.

    For details see the documentation for the above mentioned functions. To get a better understanding of the difference between drawing in drawRect: and in arbitrary place in your program and of working with contexts in general, I would recommend you read the Quartz2D Programming Guide, especially the section on Graphics Contexts.

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

Sidebar

Related Questions

I'm trying to implement the following method: void Ball::DrawOn(Graphics g); The method should draw
Hey everyone, my first time trying to draw a multi-color gradient in actionscript 3.
In a sub-class of JComponent I am overriding paintComponent method to draw. The first
I want to draw a manipulated graphic into another: // I have two graphics:
I have winform with a TextBox and I want to draw some GDI graphics
I've recently taken my first step into GDI+, and am trying to draw an
This is probably a simple thing. I'm trying to draw my first shapes in
I want to draw a circle which has the follow properties: Center is the
first of all, sorry if that question is dumb but I´m a total newbie
First of all, what's the difference between: www.domain.com and domain.com Should I pay attention

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.