Create a screensaver tutorial?

Discussion in 'iOS Programming' started by BollywooD, Oct 1, 2008.

  1. BollywooD macrumors 6502


    Apr 27, 2005
    is there such a thing....

    I would like to build a simple screensaver app, but have no idea where to start, does anyone have any tips?

    Cheers in advance
  2. ilikeleopard macrumors newbie

    Aug 17, 2010
    Before you get started writing screen savers, I suggest you learn how to draw in a custom view. A suggested tutorial to do so is at
    That should prepare you to draw anything in Cocoa.

    So you want to make screen savers, eh?
    It's actually quite simple.
    To begin, go to open XCode, and then open a new project. XCode on :apple: Leopard lets you make a Screen Saver project, but I'm not quite sure about any other version. I'm sure if you look hard enough, you will find a screen saver somewhere. Since this is presumably the first screen saver you make, name it "HelloSaver".It will draw the text "Hello, World!" in white on the black~ish background.

    go to HelloSaver.h. As you may notice, it inherits from the ScreenSaverView class, which is a subclass of the NSView class. If you know how to draw in a customized view, it's basically the same, except if you put your drawing code in the drawRect: method, you will have to change the animateOneFrame: method to look like

    -(void) animateOneFrame{
    [super animateOneFrame];//I'm not sure this is required, but it can't hurt.
    [self setNeedsDisplay:Yes];//tells the computer to draw the view with the drawRect: method instead
    And now to do the actual drawing:
    override the drawRect: method:

    -(void) drawRect: (NSRect) aRect{
    [super drawRect:aRect];//this is required to make it white.
    NSString* aString = @"Hello, World!";
    NSColor* fgColor = [NSColor white];//because we want it to draw white.
    NSMutableDictionary* md = [NSMutableDictionary dictionaryWithCapacity:1];
    [md setValue:fgColor forObject:NSForegroundColorAttributeName];
    NSAttributedString* drawn = [[NSAttributedString alloc] initWithString:aString
    attributes: md];
    [drawn drawInRect:rect];//could also use [self bounds]
    Now all you need to do is compile it and double-click on HelloSaver.saver, and your saver is installed for testing.

    I'm not on my mac right now, so I could have made a few errors. If it doesn't compile right or if there are lots of warnings, check the areas with the documentation at or on XCode. I hope this helps.

    One last thing: if you aren't that much of a coder, you could easily put together a simple screen saver in Quartz Composer from the simple screen saver template, and put it in your "~/library/screen savers/" folder, but I wouldn't recommend releasing a screen saver that way.

    edit: oops. I didn't see that this post was in the iPhone/iPad programming section. But I guess it's too late now.
  3. ChOas macrumors regular

    Nov 24, 2006
    The Netherlands
    It's also almost 2 years old ;)

Share This Page