CG help: how to get something to draw (very simple)

Discussion in 'iOS Programming' started by foges, Jun 14, 2010.

  1. foges macrumors newbie

    Joined:
    May 5, 2009
    #1
    Hello people, Im an absolute newb here but anyways. I created a new view based application and pasted the following code into the ViewController.m file, what else do i need to do to get it to display:

    Code:

    Code:
    - (void)drawRect:(CGRect)rect
    {
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        CGContextClearRect(ctx, rect);
    }
    Im sorry for the simple question, but i cant seem to find any good CG tutorials
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    What are you expecting that to display? All you are doing is clearing a rectangle back to the background.
     
  3. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #3
    <http://www.cocoadevcentral.com/d/intro_to_quartz_two/>
     
  4. foges thread starter macrumors newbie

    Joined:
    May 5, 2009
    #4
    oops sorry, incomplete code, here is what i meant to post:

    Code:
    -(void)drawRect:(CGRect)rect
    {
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        CGContextClearRect(ctx, rect);
    	CGContextSetRGBFillColor(ctx, 255, 0, 0, 1);
        CGContextFillRect(ctx, CGRectMake(10, 10, 50, 50));
    }
    Thanks ill check out that link
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    I posted some of my code some time ago that shows how I draw a couple of the iPhone system images in core graphics to get them in different colours. I render into images but the basics are the same.

    http://forums.macrumors.com/showthread.php?t=884715
     
  6. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    Look at the quartz demo example code and then look at the quartz docs. A view controller doesn't get drawn. Only views get drawn.
     

Share This Page