What I am trying to accomplish is drawing curved lines from a center of a view. So far with the help of much googling and this site...I've accomplished the image below.
http://www.flickr.com/photos/57562417#N00/9100635690/
What I would like to do is have curved lines like the following image...
http://www.flickr.com/photos/57562417#N00/9100634674/
Any and all help would be appreciated. I've included the code thus far.
#import <UIKit/UIKit.h>
#interface ChartView : UIView
#property (nonatomic,assign) int angle;
#end
----------------------------------------------------------------------
#import "ChartView.h"
#import <QuartzCore/QuartzCore.h>
/** Helper Functions **/
#define degree_to_radians(deg) ( (M_PI * (deg)) / 180.0 )
#define radians_to_degrees(rad) ( (180.0 * (rad)) / M_PI )
#interface ChartView(){
int radius;
}
#end
#implementation ChartView
-(id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
self.backgroundColor = [UIColor whiteColor];
[self.layer setBorderWidth:1.0];
[self.layer setBorderColor:[UIColor redColor].CGColor];
//Define the circle radius taking into account the safe area
radius = self.frame.size.width/2;
//Initialize the Angle at 0
self.angle = 360;
}
return self;
}
-(void)drawRect:(CGRect)rect{
//Circle center
int numberOfSections = 96; //24 major lines
CGFloat angleSize = 2 * M_PI/numberOfSections;
CGContextRef context = UIGraphicsGetCurrentContext();
//draw the main outside circle
CGRect circleRect = CGRectMake(0.0, 0.0, 720., 720.);
CGContextSetLineWidth(context, .5);
CGContextSetRGBStrokeColor(context, 0.0, 2.0, 4.0, 1.0);
CGContextStrokeEllipseInRect(context, circleRect);
CGPoint centerPoint = CGPointMake(circleRect.size.width/2 , circleRect.size.height/2);
//setup for drawing lines from center, straight lines, need curved lines
CGContextTranslateCTM(context, 0.0, 0.0);
for (int x = 0; x < numberOfSections; x++) {
CGContextSetLineWidth(context, .5);
CGContextSetRGBStrokeColor(context, 0.0, 2.0, 4.0, 1.0);
CGContextMoveToPoint(context, self.frame.size.width/2, self.frame.size.height/2);
CGContextAddLineToPoint(context, centerPoint.x + radius * cos(angleSize * x) ,centerPoint.y + radius * sin(angleSize * x));
CGContextStrokePath(context);
}
CGContextSetLineWidth(context, .5);
CGContextSetRGBStrokeColor(context, 0.0, 2.0, 4.0, 1.0);
CGContextSetRGBFillColor(context, 1., 1., 1., 1.0);
//Taken from Hypnotizer code
float maxRadius = 360.0;
CGContextSetLineWidth(context, 0.5f);
CGContextSetRGBStrokeColor(context, 0.0, 2.0, 4.0, 1.0);
//need to add 100 lines form a certain radius to a max radius
for (float currentRadius = maxRadius; currentRadius > 99; currentRadius -=2.6) {
CGContextAddArc(context, centerPoint.x, centerPoint.y, currentRadius, 0.0, M_PI * 2.0, YES);
CGContextStrokePath(context);
}
}
#end
Alright, I've got some code for you that I tried out and does the curved line effect you mentioned in that second picture:
- (void)drawRect:(CGRect)rect {
radius = self.frame.size.width / 2;
// Circle center
int numberOfSections = 96; // 24 major lines
CGFloat angleSize = 2 * M_PI/ numberOfSections;
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect circleRect = CGRectMake(0.0, 0.0, 720., 720.);
CGPoint centerPoint = CGPointMake(circleRect.size.width / 2, circleRect.size.height / 2);
/* Create mask to create 'hole' in the center */
CGContextAddArc(context, centerPoint.x, centerPoint.y, 720 / 2.0, 0.0, M_PI * 2.0, YES);
CGContextAddArc(context, centerPoint.x, centerPoint.y, 100, 0.0, M_PI * 2.0, NO);
CGContextClip(context);
// draw the main outside circle
CGContextSetLineWidth(context, .5);
CGContextSetRGBStrokeColor(context, 0.0, 2.0, 4.0, 1.0);
CGContextStrokeEllipseInRect(context, circleRect);
// setup for drawing lines from center, straight lines, need curved lines
CGContextTranslateCTM(context, 0.0, 0.0);
for (int x = 0; x < numberOfSections; x++) {
CGContextSetLineWidth(context, .5);
CGContextSetRGBStrokeColor(context, 0.0, 2.0, 4.0, 1.0);
double angle = angleSize * x;
CGPoint outsidePoint = CGPointMake(centerPoint.x + radius * cos(angle), centerPoint.y + radius * sin(angle));
CGPoint control1 = CGPointMake(centerPoint.x + radius/3 * cos(angle-0.5), centerPoint.y + radius/3 * sin(angle-0.5));
CGPoint control2 = CGPointMake(centerPoint.x + (2*radius/3) * cos(angle-0.5), centerPoint.y + (2*radius/3) * sin(angle-0.5));
UIBezierPath *bezierPath = [UIBezierPath bezierPath];
[bezierPath moveToPoint:CGPointMake(circleRect.size.width / 2, circleRect.size.height / 2)];
[bezierPath addCurveToPoint:outsidePoint controlPoint1:control1 controlPoint2:control2];
CGContextAddPath(context, bezierPath.CGPath);
CGContextStrokePath(context);
}
CGContextSetLineWidth(context, .5);
CGContextSetRGBStrokeColor(context, 0.0, 2.0, 4.0, 1.0);
CGContextSetRGBFillColor(context, 1., 1., 1., 1.0);
// Taken from Hypnotizer code
float maxRadius = 360.0;
CGContextSetLineWidth(context, 0.5f);
CGContextSetRGBStrokeColor(context, 0.0, 2.0, 4.0, 1.0);
// need to add 100 lines form a certain radius to a max radius
for (float currentRadius = maxRadius; currentRadius > 99; currentRadius -= 2.6) {
CGContextAddArc(context, centerPoint.x, centerPoint.y, currentRadius, 0.0, M_PI * 2.0, YES);
CGContextStrokePath(context);
}
}
Related
iOS 10.2 Swift 3.0
Trying to convert this code in objective C to Swift 3.0 and don't know the core graphics library too well.
#interface SPGripViewBorderView : UIView
#end
#implementation SPGripViewBorderView
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Clear background to ensure the content view shows through.
self.backgroundColor = [UIColor clearColor];
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
// (1) Draw the bounding box.
CGContextSetLineWidth(context, 1.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextAddRect(context, CGRectInset(self.bounds, kSPUserResizableViewInteractiveBorderSize/2, kSPUserResizableViewInteractiveBorderSize/2));
CGContextStrokePath(context);
// (2) Calculate the bounding boxes for each of the anchor points.
CGRect upperLeft = CGRectMake(0.0, 0.0, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
CGRect upperRight = CGRectMake(self.bounds.size.width - kSPUserResizableViewInteractiveBorderSize, 0.0, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
CGRect lowerRight = CGRectMake(self.bounds.size.width - kSPUserResizableViewInteractiveBorderSize, self.bounds.size.height - kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
CGRect lowerLeft = CGRectMake(0.0, self.bounds.size.height - kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
CGRect upperMiddle = CGRectMake((self.bounds.size.width - kSPUserResizableViewInteractiveBorderSize)/2, 0.0, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
CGRect lowerMiddle = CGRectMake((self.bounds.size.width - kSPUserResizableViewInteractiveBorderSize)/2, self.bounds.size.height - kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
CGRect middleLeft = CGRectMake(0.0, (self.bounds.size.height - kSPUserResizableViewInteractiveBorderSize)/2, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
CGRect middleRight = CGRectMake(self.bounds.size.width - kSPUserResizableViewInteractiveBorderSize, (self.bounds.size.height - kSPUserResizableViewInteractiveBorderSize)/2, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
// (3) Create the gradient to paint the anchor points.
CGFloat colors [] = {
0.4, 0.8, 1.0, 1.0,
0.0, 0.0, 1.0, 1.0
};
CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents(baseSpace, colors, NULL, 2);
CGColorSpaceRelease(baseSpace), baseSpace = NULL;
// (4) Set up the stroke for drawing the border of each of the anchor points.
CGContextSetLineWidth(context, 1);
CGContextSetShadow(context, CGSizeMake(0.5, 0.5), 1);
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
// (5) Fill each anchor point using the gradient, then stroke the border.
CGRect allPoints[8] = { upperLeft, upperRight, lowerRight, lowerLeft, upperMiddle, lowerMiddle, middleLeft, middleRight };
for (NSInteger i = 0; i < 8; i++) {
CGRect currPoint = allPoints[i];
CGContextSaveGState(context);
CGContextAddEllipseInRect(context, currPoint);
CGContextClip(context);
CGPoint startPoint = CGPointMake(CGRectGetMidX(currPoint), CGRectGetMinY(currPoint));
CGPoint endPoint = CGPointMake(CGRectGetMidX(currPoint), CGRectGetMaxY(currPoint));
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
CGContextRestoreGState(context);
CGContextStrokeEllipseInRect(context, CGRectInset(currPoint, 1, 1));
}
CGGradientRelease(gradient), gradient = NULL;
CGContextRestoreGState(context);
}
#end
Which I re-coded as this ...
import UIKit
class GripViewBorderView: UIView {
let kUserResizableViewInteractiveBorderSize:CGFloat = 10.0
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect) {
super.init(frame: frame)
}
override func draw(_ rect:CGRect) {
let context = UIGraphicsGetCurrentContext();
context!.saveGState();
// (1) Draw the bounding box.
context!.setLineWidth(1.0);
context!.setStrokeColor(UIColor.blue.cgColor)
//CGContextAddRect(context!, CGRectInset(self.bounds, (kSPUserResizableViewInteractiveBorderSize / 2.0), (kSPUserResizableViewInteractiveBorderSize / 2.0)));
context!.addRect(self.bounds.insetBy(dx: (kUserResizableViewInteractiveBorderSize / 2.0), dy: (kUserResizableViewInteractiveBorderSize / 2.0)))
context!.strokePath();
// (2) Calculate the bounding boxes for each of the anchor points.
let upperLeft = CGRect(x: 0.0, y: 0.0, width: kUserResizableViewInteractiveBorderSize, height: kUserResizableViewInteractiveBorderSize)
let upperRight = CGRect(x: self.bounds.size.width - kUserResizableViewInteractiveBorderSize, y: 0.0, width: kUserResizableViewInteractiveBorderSize, height: kUserResizableViewInteractiveBorderSize);
let lowerRight = CGRect(x: self.bounds.size.width - kUserResizableViewInteractiveBorderSize, y: self.bounds.size.height - kUserResizableViewInteractiveBorderSize, width: kUserResizableViewInteractiveBorderSize, height: kUserResizableViewInteractiveBorderSize);
let lowerLeft = CGRect(x: 0.0, y: self.bounds.size.height - kUserResizableViewInteractiveBorderSize, width: kUserResizableViewInteractiveBorderSize, height: kUserResizableViewInteractiveBorderSize);
let upperMiddle = CGRect(x: (self.bounds.size.width - kUserResizableViewInteractiveBorderSize)/2, y: 0.0, width: kUserResizableViewInteractiveBorderSize, height: kUserResizableViewInteractiveBorderSize);
let lowerMiddle = CGRect(x: (self.bounds.size.width - kUserResizableViewInteractiveBorderSize)/2, y: self.bounds.size.height - kUserResizableViewInteractiveBorderSize, width: kUserResizableViewInteractiveBorderSize, height: kUserResizableViewInteractiveBorderSize);
let middleLeft = CGRect(x: 0.0, y: (self.bounds.size.height - kUserResizableViewInteractiveBorderSize)/2, width: kUserResizableViewInteractiveBorderSize, height: kUserResizableViewInteractiveBorderSize);
let middleRight = CGRect(x: self.bounds.size.width - kUserResizableViewInteractiveBorderSize, y: (self.bounds.size.height - kUserResizableViewInteractiveBorderSize)/2, width: kUserResizableViewInteractiveBorderSize, height: kUserResizableViewInteractiveBorderSize);
// (3) Create the gradient to paint the anchor points.
let baseSpace = CGColorSpaceCreateDeviceRGB()
//let gradient = CGGradientCreateWithColorComponents(baseSpace, colors, NULL, 2)
let colors = [UIColor.red.cgColor,
UIColor.yellow.cgColor]
let gradient = CGGradient(colorsSpace: baseSpace, colors: colors as CFArray, locations: nil)
// (4) Set up the stroke for drawing the border of each of the anchor points.
context!.setLineWidth(1)
context!.setShadow(offset: CGSize(width: 0.5, height: 0.5), blur: 1)
context!.setStrokeColor(UIColor.white.cgColor)
// (5) Fill each anchor point using the gradient, then stroke the border.
let allPoints:[CGRect] = [ upperLeft, upperRight, lowerRight, lowerLeft, upperMiddle, lowerMiddle, middleLeft, middleRight ];
for i in 0 ... 7 {
let currPoint = allPoints[i]
context!.saveGState()
context!.addEllipse(in: currPoint)
context!.clip()
let startPoint = CGPoint(x: currPoint.midX, y: currPoint.minY);
let endPoint = CGPoint(x: currPoint.midX, y: currPoint.maxY);
context!.drawLinearGradient(gradient!, start: startPoint, end: endPoint, options: .init(rawValue: 0))
context!.saveGState()
context!.strokeEllipse(in: currPoint.insetBy(dx: 1, dy: 1))
}
context!.restoreGState()
}
}
But I missed something cause the OOC is on the left and my new Swift on the right. For reasons I cannot figure I get only a single dot drawn in my version, the OOC version draws 8 dots [correctly].
You have written context!.saveGState() at the end of the for loop in place of CGContextRestoreGState(context). It should, of course, be context!.restoreGState(). Simple typo!
Also, please remove all of the semi-colons, and use guard let context = UIGraphicsGetCurrentContext() else { return } to get rid of all those forced unwrappings!
I have succeeded in drawing a rectangle which has a hole inside of the shape of a rounded rectangle using CGContextEOFillPath. I can change the colour of my shape. However, I would like to use a gradient, I suppose that I have got to use CGContextDrawLinearGradient, however, I can't make it work. It keep painting the entire rectangle, hole included.
Here is the code that I am using
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGFloat frameWidth = 1; //[CQMFloatingContentOverlayView frameWidth];
CGFloat radius = [self cornerRadius];
CGSize viewSize = [self frame].size;
CGPathRef path = CQMPathCreateRoundingRect(CGRectMake(frameWidth, frameWidth,
viewSize.width - frameWidth * 2,
viewSize.height - frameWidth * 2),
radius, radius, radius, radius);
CGContextAddRect(context, CGRectMake(0, 0, viewSize.width, viewSize.height));
CGContextAddPath(context, path);
CGContextEOFillPath(context);
CGPathRelease(path);
CGContextRestoreGState(context);
}
CGPathRef CQMPathCreateRoundingRect(CGRect rect, CGFloat blRadius, CGFloat brRadius, CGFloat trRadius, CGFloat tlRadius) {
CGPoint tlPoint = rect.origin;
CGPoint brPoint = CGPointMake(rect.origin.x + rect.size.width,
rect.origin.y + rect.size.height);
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, tlPoint.x + tlRadius, tlPoint.y);
CGPathAddArcToPoint(path, NULL,
brPoint.x, tlPoint.y,
brPoint.x, tlPoint.y + trRadius,
trRadius);
CGPathAddArcToPoint(path, NULL,
brPoint.x, brPoint.y,
brPoint.x - brRadius, brPoint.y,
brRadius);
CGPathAddArcToPoint(path, NULL,
tlPoint.x, brPoint.y,
tlPoint.x, brPoint.y - blRadius,
blRadius);
CGPathAddArcToPoint(path, NULL,
tlPoint.x, tlPoint.y,
tlPoint.x + tlRadius, tlPoint.y,
tlRadius);
CGPathCloseSubpath(path);
return path;
}
I don't know where to put the gradient code, I have tried before and after the CGContextEOFillPath but could not reach my objective.
This code should make what you want (check for syntax and typos, code is directly written in answer)
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat gradientColors[] =
{
0.1, 0.1, 0.5, 1.00,
0.9, 0.9, 1.0, 1.00,
};
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, gradientColors, NULL, sizeof(gradientColors)/(sizeof(gradientColors[0])*4));
CGColorSpaceRelease(colorSpace);
CGContextSaveGState(context);
CGFloat frameWidth = 1; //[CQMFloatingContentOverlayView frameWidth];
CGFloat radius = [self cornerRadius];
CGSize viewSize = [self frame].size;
CGPathRef path = CQMPathCreateRoundingRect(CGRectMake(frameWidth, frameWidth,
viewSize.width - frameWidth * 2,
viewSize.height - frameWidth * 2),
radius, radius, radius, radius);
CGContextAddRect(context, CGRectMake(0, 0, viewSize.width, viewSize.height));
CGContextAddPath(context, path);
CGContextEOClip(context);
CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(viewSize.width, viewSize.height), kCGGradientDrawsBeforeStartLocation);
CGPathRelease(path);
CGContextRestoreGState(context);
}
Im trying to stroke and fill a path for an overlay view for a MapView. Now the fill works, the stroke doesnt... Any ideas from looking at the code below?
- (void)drawMapRect:(MKMapRect)mapRect
zoomScale:(MKZoomScale)zoomScale
inContext:(CGContextRef)ctx
{
CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 0.8);
CGContextSetRGBFillColor(ctx, 0.0, 0.0, 0.8, 0.4);
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineWidth(ctx, 8.0);
CGPoint pt;
pt = [self pointForMapPoint:MKMapPointForCoordinate(CLLocationCoordinate2DMake(0, 0))];
CGContextMoveToPoint(ctx, pt.x, pt.y);
pt = [self pointForMapPoint:MKMapPointForCoordinate(CLLocationCoordinate2DMake(-2, 3))];
CGContextAddLineToPoint(ctx, pt.x, pt.y);
pt = [self pointForMapPoint:MKMapPointForCoordinate(CLLocationCoordinate2DMake(-2, 5))];
CGContextAddLineToPoint(ctx, pt.x, pt.y);
pt = [self pointForMapPoint:MKMapPointForCoordinate(CLLocationCoordinate2DMake(-4, 4))];
CGContextAddLineToPoint(ctx, pt.x, pt.y);
CGContextDrawPath(ctx, kCGPathFillStroke);
}
This made it work...
CGContextSetLineWidth(ctx, 1 * MKRoadWidthAtZoomScale(zoomScale));
I want to draw bar with a cylindrical look and with shadow effect(As shown in the below image). Can some one help to define Linear Gradient for below look and feel.
Code:
-(void)drawRect:(CGRect)rect {
//UIview Back color is red or green
CGGradientRef glossGradient;
CGColorSpaceRef rgbColorspace;
CGContextRef currentContext = UIGraphicsGetCurrentContext();
size_t num_locations = 4;
CGFloat locations[4] = { 0.0,0.7,0.9,1.0 };
CGFloat components[16] = { 0.0, 0.0, 0.0, 0.01,
0.0, 0.0, 0.0, 0.1,
0.0, 0.0, 0.0, 0.2,
0.0, 0.0, 0.0, 0.5
};
rgbColorspace = CGColorSpaceCreateDeviceRGB();
glossGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);
CGRect currentBounds = self.bounds;
CGPoint topCenter = CGPointMake(CGRectGetMidX(currentBounds), 0.0f);
CGPoint midCenter = CGPointMake(CGRectGetMidX(currentBounds), currentBounds.size.height);
CGContextDrawLinearGradient(currentContext, glossGradient, topCenter, midCenter, 0);
CGGradientRelease(glossGradient);
CGColorSpaceRelease(rgbColorspace);
}
Here's a general purpose gradient maker:
CGGradientRef makeGradient2(NSArray *colors, CGFloat *stops)
{
size_t nc = 4;
NSInteger colorSize = nc * sizeof(CGFloat);
CGFloat *theComponents = malloc( [colors count] * colorSize );
CGFloat *compPtr = theComponents;
for (int i=0; i < colors.count; i++){
UIColor *color = [colors objectAtIndex:i];
CGColorRef cgColor = [color CGColor];
const CGFloat *components = CGColorGetComponents(cgColor);
memmove(compPtr, components, colorSize);
compPtr += nc;
}
CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents (cs, theComponents, stops, colors.count);
CGColorSpaceRelease(cs);
free(theComponents);
return gradient;
}
call it like (this creates a three part gray gradient with lightest in the middle)
CGFloat stops[] = { 0.0, 0.5, 1.0};
gradient = makeGradient2([NSArray arrayWithObjects:
[UIColor colorWithRed:.2 green:.2 blue:.2 alpha:1.0],
[UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1.0],
[UIColor colorWithRed:.2 green:.2 blue:.2 alpha:1.0],
nil], stops);
and then you can draw with it like (for a left to right gradient):
CGContextDrawLinearGradient(gc, gradient, CGPointMake(0.0, 0.0), CGPointMake(rect.size.width, 0.0), 0);
Instruments shows me that I have a leak in the following code:
CGContextMoveToPoint(c, startPoint.x, self.frame.size.height - offsetYBottom);
CGContextAddLineToPoint(c, startPoint.x, startPoint.y);
CGContextAddLineToPoint(c, endPoint.x, endPoint.y);
CGContextAddLineToPoint(c, endPoint.x, self.frame.size.height - offsetYBottom);
CGContextClosePath(c);
CGGradientRef myGradient;
CGColorSpaceRef myColorspace;
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
CGFloat components[8] = { 0.0/255.0, 197.0/255.0, 254.0/255.0, 1.0f, 0.0/255.0, 197.0/255.0, 254.0/255.0, 0.25f };
myColorspace = CGColorSpaceCreateDeviceRGB();
myGradient = CGGradientCreateWithColorComponents (myColorspace, components, locations, num_locations);
CGPoint myStartPoint, myEndPoint;
myStartPoint.x = self.frame.size.width / 2;
myStartPoint.y = 0.0;
myEndPoint.x = self.frame.size.width / 2;
myEndPoint.y = self.frame.size.height;
CGContextSaveGState(c);
CGContextClip(c);
CGContextDrawLinearGradient (c, myGradient, myStartPoint, myEndPoint, 0);
CGContextRestoreGState(c);
If I comment this portion, the leaks are gone.
startPoint and endPoint are CGPoint.
Responsible caller: CGTypeCreateInstanceWithAllocator.
What could be the problem?
Following the Create Rule, you have to release myColorspace and myGradient when you're done with them:
CGColorSpaceRelease(myColorspace);
CGGradientRelease(myGradient);
Try to release myGradient object
CGGradientRelease(myGradient);