Archive for August, 2011

Mii: Laura

Name: Laura Kritzinger
Nickname: Leia
Likes: Gadgets…kitchen gadgets..
Dislikes: Steve’s MK noises
Speciality (what we go to Laura for): All the little things that make Cobi run smoothly
MK signature move: Feeds us real life power ups to create more energetic MK games


Quick and Easy iPhone Gradients

The market for iPhone and iPad apps is competitive and sometimes a bit of extra eye-candy goes a long way. For a couple of projects I have had to give various items a gradient shaded background. There are two ways to do this. Core Graphics or Core Animation. Gradients in Core Graphics give you more customization and more control, but are more complex to implement, while gradients in Core Animation are simple, but may not be able to do everything you need. Here we are going to look are the fast Core Animation approach.

Make sure you #import <QuartzCore/QuartzCore.h>

To make a simple rectangular gradient all we need is to add a CAGradientLayer:

CAGradientLayer * gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = CGRectMake(0, 0, 80, 60);
gradientLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor redColor] CGColor],(id)[[UIColor greenColor] CGColor], nil];
[self.window.layer addSublayer:gradientLayer];

This produces a rectangle that can be used in any view:

We can give the layer rounded corners by adding:

gradientLayer.cornerRadius = 10;

For more complex shapes we can set a mask for the gradient layer using a CAShapeLayer:
//Make shape – Triangle
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL,40.0f, 0.0f);
CGPathAddLineToPoint (path, NULL,80.0f, 60.0f);
CGPathAddLineToPoint (path, NULL,0.0f, 60.0f);
CGPathCloseSubpath(path);

//Shape layer
CAShapeLayer * mask = [CAShapeLayer layer];
mask.path = path;
[gradientLayer setMask:mask];

//release path
CGPathRelease(path);

UIButton with a gradient:

 

The graph I made for a project using Core Animation layers:


Cobi is 2!!


We’ve made the 2 year mark and still going strong. A lot has happened in the past year. We’ve grown from a team of 3 to a team of 7, we a have a real office, some exciting projects and a lot more exciting mario kart sessions. Thanks to the Cobi team for all the hard work.


  • Topics

  • Archive

    August 2011
    S M T W T F S
    « Jul   Sep »
     123456
    78910111213
    14151617181920
    21222324252627
    28293031  
  • Copyright © 2010 Cobi Interactive (Pty) Ltd. All rights reserved.
    Jarrah theme by Templates Next | Powered by WordPress