views:

314

answers:

4
+2  A: 

It would not be hard to create a UIView subclass for this purpose. In the subclass you would want to do roughly the following in the drawRect routine:

CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat      center_x = self.frame.size.width / 2;
CGFloat      center_y = self.frame.size.height / 2;
double       progress = 0.42; // A floating-point number from 0..1 inclusively

// draw the frame
CGContextAddArc(context,
                center_x,
                center_y,
                std::min(self.frame.size.width, self.frame.size.height),
                0,
                M_PI * 2,
                1 /*clockwise*/);
CGContextStrokePath(context);

// draw the progress indicator
CGContextAddArc(context,
                center_x,
                center_y,
                std::min(self.frame.size.width, self.frame.size.height),
                0,
                M_PI * 2 * progress,
                1 /*clockwise*/);
CGContextFillPath(context);
fbrereto
Minor point: those CGPoint variables should be declared as CGFloat.
Don
Thank you sir
fbrereto
A: 

You mean a progress indicator, such as the one included in Interface Builder, but circular? I assume there's a default one in the Flex framework that you've seen the tutorials for.

I think you'll have to make this on your own. What you could do is have a view that listens for notifications of progress from an object. When it receives these, you would calculate the image to display and call the viewNeedsDisplay method.

I took a quick glance at the Sequel Pro source, and I think what you're looking for is the NSProgressIndicator. But Sequel Pro is a desktop app and has more flexibility than the iPhone. The Cocoa Touch equivalent would be UIActivityIndicatorView, which is always indeterminate (i.e., you can't specify percent completed).

Edit: yes, see fbrereton's code above for drawing routine.

And here's how you'd listen for notifications to get that progress floating-point value:

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(receivedProgress:)
                                                 name:@"MyProgressIndication" 
                                               object:nil];

You'd post them from the object that's doing the work like this:

    [[NSNotificationCenter defaultCenter] postNotificationName:@"MyProgressIndication"
                                                        object:[NSNumber numberFromFloat:progress]];

A constant for the notification name would be best.

Don
A: 

You should use the AnimatedGif library, and download an animated GIF from preloaders.net or something.

Just do it programatically (without IB). It's very simple. Here's the code:

AnimatedGif *animatedGif = [[[AnimatedGif alloc] init] autorelease];    
NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"circle-loader" ofType:@"gif"]]; 
[animatedGif decodeGIF: data];
self.loadingImage = [animatedGif getAnimation]; //self.loadingImage is a UIImageView
[self.view addSubview:loadingImage];

Then, later when you want to remove the GIF:

[loadingImage removeFromSuperview];
[loadingImage release];
Andrew Johnson
A: 

The AnimatedGif(referenced above) Library works really well. Had to dig to find it here: http://blog.stijnspijker.nl/2009/07/animated-and-transparent-gifs-for-iphone-made-easy/