- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
	CGContextRef	context = UIGraphicsGetCurrentContext();	
    
 	
    if(m_square){
        
        CGContextSetRGBStrokeColor(context, 1.0, 1.0, 0.0, 1.0); // yellow line
        
        CGContextBeginPath(context);
        
        CGContextMoveToPoint(context, 50.0, 50.0); //start point
        CGContextAddLineToPoint(context, 250.0, 100.0);
        CGContextAddLineToPoint(context, 250.0, 350.0);
        CGContextAddLineToPoint(context, 50.0, 350.0); // end path
        
        CGContextClosePath(context); // close path
        
        CGContextSetLineWidth(context, 8.0); // this is set from now on until you explicitly change it
        
        CGContextStrokePath(context); // do actual stroking
        
        CGContextSetRGBFillColor(context, 0.0, 1.0, 0.0, 0.5); // green color, half transparent
        CGContextFillRect(context, CGRectMake(20.0, 250.0, 128.0, 128.0)); // a square at the bottom left-hand corner
        
    }
}

 

sample code:

Tutorial_Quartz_Circle_Square

 

reference:

http://www.codeproject.com/KB/iPhone/iOSGetStarted01.aspx

 

By admin-powenko

Dr. Powen Ko is a teacher and CEO on LoopTek LLC, and like to teaching. if you need to class, please let PowenKo know, he will love to service and sharing. LoopTek web site is www.looptek.com

Leave a Reply