Last Updated: February 25, 2016
·
2.114K
· bolomichelin

# Gold Challenge : Chapter 6 - iOS Programming: The Big Nerd Ranch Guide (3rd Edition)

I am leaning IOS at the moment with "iOS Programming: The Big Nerd Ranch Guide"
Most chapters in this book finished with 3 challenges - Bronze - Silver and Gold.
I will share with you my code for Gold Challenges. :

• draw a image
• mask the image with circle

my code

``````- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
UIImage *img = [UIImage imageNamed:@"Icon@2x.png"];
CGRect bounds = [self bounds];
CGPoint center;
center.x = bounds.origin.x + bounds.size.width / 2.0;
center.y = bounds.origin.y + bounds.size.height / 2.0;
float maxRadius = hypot(bounds.size.width, bounds.size.height) / 3.0;

CGContextSaveGState(ctx);
CGContextSetShadowWithColor(ctx, CGSizeMake(0, 1), 2, [[UIColor blackColor] CGColor]);
CGContextStrokePath(ctx);
CGContextRestoreGState(ctx);
CGContextClip(ctx);

[img drawInRect:bounds];
CGColorSpaceRef colorSpace  = CGColorSpaceCreateDeviceRGB();
CGFloat colorList[] ={
173.0/255.0, 216.0/255.0,230.0/255.0, 1.0, //red, green, blue, alpha
1.0, 1.0, 1.0, 0.5};

CGFloat locationList[3] = {0.0, 1};
CGPoint startPoint, endPoint;
startPoint.x = bounds.size.width / 2.0; // center
startPoint.y = 0;
endPoint.x =  bounds.size.width / 2.0;
endPoint.y = bounds.size.height / 2.0;
//CGContextClip(ctx);
}``````

797
0

310.9K
13

### Swift: Instantiate a view controller using its Storyboard name in Xcode

145.3K
0

#### Have a fresh tip? Share with Coderwall community!

Best #Ios Authors
itseranga
464.8K
kanshuYokoo
114.6K
chrishannah
101.9K
Related Tags
#ios
#tutorial
Filed Under

Awesome Job