# My Gold Challenge Approach

#1

Hi everyone,

This has been a real challenge for me, I tried for almost 2 days (yeah embarrassing) and now I’m stuck 'cause NOT ANYMORE!! I just figure it out… really, I finally did it.

[size=200]Gold Challenge Solution[/size]

[code]#import <Foundation/Foundation.h>
#import “MRCHypnosisView.h”

@interface MRCHypnosisterBNRLogo : MRCHypnosisView

@property (strong, nonatomic) UIImage *bnrLogo;

@end[/code]

[size=150]Implementation File[/size]

[code]#import “MRCHypnosisterBNRLogo.h”

@implementation MRCHypnosisterBNRLogo
@synthesize bnrLogo;

-(id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self setBackgroundColor:[UIColor clearColor]];
}
return self;
}

• (void)drawRect:(CGRect)circleLogo
{
/********************************************************************************************************/
//Create the CGRect struct and find its center

//Pick a pointer to the current context (struct)
CGContextRef contextRef = UIGraphicsGetCurrentContext();

//Define the bounds of the frame for the logo
CGRect logoBNR = [self bounds];

//Define the center point of the rectangle
CGPoint rectCenter;
rectCenter.x = logoBNR.size.width / 2.0;
rectCenter.y = logoBNR.size.height / 2.0;

/********************************************************************************************************/
//Define the parameters for the circle, its stroke line, its shadow and add the image to the frame

//Define the radius for the circle
float circleRadius = hypotf(logoBNR.size.width, logoBNR.size.height) / 3.0;

//Set the color for the circle line
[[UIColor blackColor] setStroke];

//Set the thickness of the line
CGContextSetLineWidth(contextRef, 0.5);

//Create an offset for shadow
CGSize shadowOffset = CGSizeMake(0, 1);

//Save current state for further drawing
CGContextSaveGState(contextRef);

//Set a pointer to a Path struct
CGMutablePathRef circlePath = CGPathCreateMutable();

//Add an arc path to the circlePath
CGPathAddArc(circlePath, NULL, rectCenter.x, rectCenter.y, circleRadius, 0.0, M_PI * 2.0, YES);

//Set the circlePath to the current path in the context

//Clip the circle path
CGContextClip(contextRef);

//Get the image and put it inside of the frame
bnrLogo = [UIImage imageNamed:@“BNRLogo.jpeg”];
[bnrLogo drawInRect:logoBNR];

/********************************************************************************************************/
//Create the blue gradient and apply it to the frame

//Create a space color ref
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceCMYK();

//Create an array of colors and cast each one of them to CGColor
NSArray *colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:0.1 green:0.2 blue:0.9 alpha:0.4] CGColor],(id)[[UIColor colorWithRed:0.0 green:0.0 blue:0.1 alpha:0.0] CGColor],nil];

//Create a pointer to a CGGradient struct with the space color and the array just created

//Set the starting point for the gradient

//Set the ending point for the gradient

/********************************************************************************************************/
//Draw the circle and add the shadow to the logo

CGContextRestoreGState(contextRef);

//Trace a path to a circle