iPhone iOS how to create graphics effects like drop shadow, etc? What effects are built-into iOS?

10,222

Solution 1

What an interesting coincidence! I've just recently held a presentation at an iOS Game Design Seminar on CoreGraphics and CoreAnimation and just today I've published some of the documents on Github.

So if you prefer some hands on examples you can check out the repository here: https://github.com/pkluz/PKCoreTechniques

Includes some of the following examples:

  • Color Fill

  • Gradient Fill (Linear and Radial)

  • Simple Paths

  • Bezier Curves

  • Clipping (Standard and Even-Odd)

  • Creating custom-drawn Buttons

  • Simple Translations

  • Translations with Hit-Test Triggers

  • A very primitive 'CoverFlow' with 3D Transformations in CoreAnimation.

.. and some more ;-)

Hope you find what you need, but from what I see it should cover a fair amount of what you've requested.

Note: There's also a PDF that serves as an interactive tutorial.

Solution 2

Here is a really good tutorial, it helped me a lot, maybe it'll help you too.

Solution 3

Here's my implementation of a radial gradient generation using CIImage. It displays the named image if a gradient was not created. Otherwise it displays a radial gradient.

+(UIImage*)doRadialGradientFilter:(NSString*)baseImageName 
{

    CIFilter* controlsFilter  = [CIFilter filterWithName: @"CIRadialGradient" keysAndValues:
                   @"inputColor1", [CIColor colorWithRed:0.0 green:0.0
                                                    blue:0.0 alpha:0.0], @"inputColor0", [CIColor colorWithRed:0.0 green:0.0
                                                                                                          blue:0.5 alpha:0.5], @"inputRadius0", [NSNumber numberWithDouble:0.0], nil];


    CIImage *displayImage = controlsFilter.outputImage;
    UIImage *finalImage = [UIImage imageWithCIImage:displayImage];

    CIContext *context = [CIContext contextWithOptions:nil];
    if (displayImage == nil || finalImage == nil) {
        // We did not get output image. Let's display the original image itself.
        return  [UIImage imageNamed:baseImageName];
    }else {
        // We got output image. Display it.
        return  [UIImage imageWithCGImage:[context createCGImage:displayImage fromRect:displayImage.extent]];
    }

}
Share:
10,222
Alex Stone
Author by

Alex Stone

When people asked me what I wanted to do for work 10 years ago, I did not know too well, so I just said "Something to do with computers". As I look at the last 10 years, I see that I did quite a lot of work all kinds of computers. From fiddling with microcontrollers and assembler code to writing data processing scripts to physically assembling computer consoles. The big step forward came when I learned to think about software in a structured, object-oriented way, as this allowed me to make software do things that I want it to do. Right now I'm proficient in two high level programming languages - Objective-C and Java and have touched just about every framework available for iOS. I've also became a hacker/maker and have completed a number of projects involving software and hardware. Right now I'm in my early 30s and when I ask myself "What would I like to do in the next 10 years?", my answer is "something with the human brain". The seeds are already there - I've picked up an interest in biology, cognitive science and neuroscience, enough to converse with real people. I've done first-hand research into sleep and made discoveries. I've taken classes in synthetic biology, performing manipulations on the bacteria genome. I've learned a lot about the neurotransmitter systems of the human brain, as well as how a biological organism develops. It seems like there are a lot of similarities between the object-oriented concepts I use in the daily programming tasks and how biological organisms operate. This makes me hopeful that by the time I'm in my late 30s, I would be able to work and program some form of biological computer or just plain hack the human brain.

Updated on July 10, 2022

Comments

  • Alex Stone
    Alex Stone almost 2 years

    I apologize for a large set of questions here. I'm starting to play with Quartz Graphics more and more, and found that it has interesting effects, yet I do not have many samples to see them in action.

     view.layer.shadowPath = [UIBezierPath bezierPathWithRect:view.bounds].CGPath;
    

    There's a shadow property:

    view.layer.shadowColor = [UIColor grayColor].CGColor;
    view.layer.shadowOffset = CGSizeMake(5, 5);
    view.layer.shadowPath = [UIBezierPath bezierPathWithRect:view.bounds].CGPath;
    view.layer.shadowRadius = 9;
    

    I was unable to make the shadow show though.

    Borders:

     view.layer.borderWidth = 1;
       view.layer.borderColor=[[UIColor whiteColor] CGColor];
    

    What other effects can I get from built-in iOS on iPhone? *Is there a comprehensive demo project that can showcase what kind of graphic manipulation functionality is built into iOS?*

    How do I do transparency masking?

    Is there a way to add inner shadow or inner glow? Is there a way to make an iOS button appear more "concave" than it really is?

    Is there a way to do radial gradients? Is there a way to create multi-ray lens flare effects like Adobe Illustrator? Is there a way to blend layers using "lighten, dissolve", or other photoshop effects? Is there a way to dynamically adjust the brightness of the image? I know how to do hue shift.

    I would appreciate any other hints on what kind of layer effects I can apply to the CALayers

  • Alex Stone
    Alex Stone about 12 years
    Thanks for a great shadow example, this is very much what I've been looking for!
  • Alex Stone
    Alex Stone about 12 years
    This is beyond great. This is simply awesome example! I see that the angry bird paths are hard-coded in. Did you type them in or use some form of code generation tool? Do you know if it's possible to get points for this path from a graphics editor, like adobe illustrator?
  • Tirth
    Tirth about 11 years
    @Templar, your given link out dated now.
  • Templar
    Templar about 11 years
    @iAmbitious Yeah, it looks like the page isn't available anymore. This is a cached-like version, but the images are missing :(