// // IGraph.m // Tutorial_Quartz_Circle // // Created by JON MOODY on 9/8/11. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import "IGraph.h" @implementation IGraph - (id)init { self = [super init]; if (self) { // Initialization code here. } return self; } - (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { // Initialization code } backgroundImage = [UIImage imageNamed:@"apple.jpg"]; m_circle=false; return self; } - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGPoint drawingTargetPoint = CGPointMake(0,0); [backgroundImage drawAtPoint:drawingTargetPoint]; if(m_circle){ CGGradientRef gradient; CGColorSpaceRef colorSpace; CGFloat locations[] = {0.0,1.0}; CGFloat components[] = { 0.5,1.0,1.0,1.0, 0.25,0.5,0.5,1.0 }; colorSpace = CGColorSpaceCreateDeviceRGB(); // colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); gradient = CGGradientCreateWithColorComponents(colorSpace,components,locations, sizeof(locations)/sizeof(CGFloat)); CGPoint start = {70.0,130.0}, end = {100.0,100.0}; CGFloat startRadius = 0.0, endRadius = 90.0; CGContextDrawRadialGradient(context,gradient,start,startRadius,end,endRadius,0); CGGradientRelease(gradient); CGColorSpaceRelease(colorSpace); } } - (void)circle{ m_circle=true; [self setNeedsDisplay]; } @end
#import <Foundation/Foundation.h> @interface IGraph : UIView { UIImage* backgroundImage; Boolean m_circle; } -(void)circle; @end
sample code:
Tutorial_Quartz_Circle