[COLOR="Red"]// Place this line into your interface file:[/COLOR]
static inline double radians (double degrees) {return degrees * M_PI/180;}
- (UIImage *) arrowBox
{
size_t width = 240;
size_t height = 160;
CGFloat arrowLength = 10.0;
CGFloat arrowWidth = 20.0;
size_t bytesPerPixel = 4;
size_t bytesPerRow = width * bytesPerPixel;
static CGColorSpaceRef colorSpace = NULL;
if (colorSpace == NULL) {
colorSpace = CGColorSpaceCreateDeviceRGB();
if (colorSpace == NULL) {
NSLog(@"EMPTY COLORSPACE!!");
return nil;
}
}
CGContextRef context = CGBitmapContextCreate(NULL, width, height, 8,
bytesPerRow, colorSpace,
kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
if (context == 0) NSLog(@"arrowBox context is nil");
CGRect tempRect;
tempRect = CGRectMake( 0.0, 0.0, width, height);
CGContextSetFillColorWithColor (context, [[UIColor yellowColor] CGColor]);
[COLOR="Red"]// Comment out this line;[/COLOR]
CGContextFillRect (context, tempRect);
CGFloat cornerRadius = 12.0;
CGSize offset = {0,-2};
CGFloat blur = 5.0;
//CGContextSetShadow (context, offset, blur);
CGContextSetShadowWithColor (context, offset, 5.0, [[UIColor blackColor] CGColor]);
CGFloat xPos = offset.width + blur;
CGFloat yPos = blur + arrowLength; //offset.height + blur;
CGFloat boxWidth = width - (xPos * 2.0);
CGFloat boxHeight = height - arrowLength - (blur * 2.0);
tempRect = CGRectMake( xPos, yPos, boxWidth, boxHeight);
CGContextSetFillColorWithColor (context, [[UIColor grayColor] CGColor]);
// Start with drawing arrow
CGContextBeginPath(context);
CGPoint arrowStartPoint = CGPointMake(xPos + cornerRadius + 3.0, yPos);
CGPoint arrowEndPoint = CGPointMake(arrowStartPoint.x + arrowWidth, yPos);
CGPoint arrowTipPoint = CGPointMake(arrowStartPoint.x + (arrowWidth / 2.0), yPos - arrowLength);
CGContextMoveToPoint(context, arrowStartPoint.x, arrowStartPoint.y);
CGContextAddLineToPoint (context, arrowTipPoint.x, arrowTipPoint.y);
CGContextAddLineToPoint (context, arrowEndPoint.x, arrowEndPoint.y);
// Lower right corner
CGContextAddArc (context,
xPos + boxWidth - cornerRadius,
arrowEndPoint.y + cornerRadius,
cornerRadius,
radians(-90.0),
radians(0.0),
0
);
// Upper right corner
CGContextAddArc (context,
xPos + boxWidth - cornerRadius,
arrowEndPoint.y + boxHeight - cornerRadius,
cornerRadius,
radians(0.0),
radians(90.0),
0
);
// Upper left corner
CGContextAddArc (context,
xPos + cornerRadius,
yPos + boxHeight - cornerRadius,
cornerRadius,
radians(90.0),
radians(180.0),
0
);
// Lower left corner
CGContextAddArc (context,
xPos + cornerRadius,
yPos + cornerRadius,
cornerRadius,
radians(180.0),
radians(270.0),
0
);
CGContextAddLineToPoint (context, arrowStartPoint.x, arrowStartPoint.y);
CGContextFillPath(context);
// ---------------------------------------------------------------------------------------
// Upper light blue
CGContextBeginPath(context);
//offset = {0,0};
CGContextSetShadowWithColor (context, offset, 0.0, [[UIColor clearColor] CGColor]);
UIColor * lightBlueColor = [UIColor colorWithRed: 0.0 green: 0.6 blue: 0.8 alpha: 1.0];
CGContextSetStrokeColorWithColor (context, [lightBlueColor CGColor]);
CGContextSetFillColorWithColor (context, [lightBlueColor CGColor]);
CGContextSetLineWidth(context, 1.0);
// CGContextMoveToPoint(context, xPos + boxWidth, arrowEndPoint.y + boxHeight - cornerRadius);
// Upper right corner
CGContextAddArc (context,
xPos + boxWidth - cornerRadius,
arrowEndPoint.y + boxHeight - cornerRadius,
cornerRadius,
radians(0.0),
radians(90.0),
0
);
// Upper left corner
CGContextAddArc (context,
xPos + cornerRadius,
yPos + boxHeight - cornerRadius,
cornerRadius,
radians(90.0),
radians(180.0),
0
);
CGContextFillPath(context);
// ---------------------------------------------------------------------------------------
// Upper dark blue
CGContextBeginPath(context);
//offset = {0,0};
CGContextSetShadowWithColor (context, offset, 0.0, [[UIColor clearColor] CGColor]);
UIColor * darkBlueColor = [UIColor colorWithRed: 0.0 green: 0.5 blue: 0.8 alpha: 1.0];
CGContextSetStrokeColorWithColor (context, [darkBlueColor CGColor]);
CGContextSetFillColorWithColor (context, [darkBlueColor CGColor]);
CGContextSetLineWidth(context, 1.0);
CGContextMoveToPoint(context, xPos + boxWidth, yPos + (boxHeight / 2.0));
// Upper right corner
CGContextAddArc (context,
xPos + boxWidth - cornerRadius,
arrowEndPoint.y + boxHeight - cornerRadius - 2,
cornerRadius,
radians(0.0),
radians(90.0),
0
);
// Upper left corner
CGContextAddArc (context,
xPos + cornerRadius,
yPos + boxHeight - cornerRadius - 2,
cornerRadius,
radians(90.0),
radians(180.0),
0
);
CGContextAddLineToPoint(context, xPos, yPos + (boxHeight / 2.0));
CGContextFillPath(context);
// ---------------------------------------------------------------------------------------
// Dividing lines
CGContextBeginPath(context);
CGContextSetLineWidth(context, 2.0);
UIColor * darkerBlueColor = [UIColor colorWithRed: 0.0 green: 0.2 blue: 0.8 alpha: 1.0];
CGContextSetStrokeColorWithColor (context, [darkerBlueColor CGColor]);
CGContextMoveToPoint(context, xPos, ((yPos + boxHeight) / 2.0) + 7.0);
CGContextAddLineToPoint(context, xPos + boxWidth, ((yPos + boxHeight) / 2.0) + 7.0);
CGContextStrokePath(context);
CGContextBeginPath(context);
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor (context, [[UIColor lightGrayColor] CGColor]);
CGContextMoveToPoint(context, xPos, ((yPos + boxHeight) / 2.0) + 4.0);
CGContextAddLineToPoint(context, xPos + boxWidth, ((yPos + boxHeight) / 2.0) + 4.0);
CGContextStrokePath(context);
// Output to a UIImage
CGImageRef cgImage = CGBitmapContextCreateImage(context);
if (!cgImage) NSLog(@"we did NOT get a gcImage ref for startButtonImage");
UIImage * arrowBoxImage = [[UIImage alloc] initWithCGImage: cgImage];
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
CGImageRelease(cgImage);
return arrowBoxImage;
}