views:

75

answers:

2

Hello,

On my iPhone app, I would need to draw a kind of full gauge with a dynamic indicator. I was thinking of using a gauge image (a .png, that I would draw in an external tool) without any indicator, and then draw the dynamic indicator on top of the image. I was thinking of using a UIView with this image in background and then then use CoreGraphics (that I've never tried) to draw the indicator.

Do you think it's the easiest way to do this ?

thanks a lot,

Luc

A: 

I think you can't have a background image in the same view.

1°) You draw the image each time drawRect() is called
2°) You have two UIView, one who have the background image, and the other one which draw your gauge ;-)

Good Luck !

(I think the easiest method is the second one which don't re-draw the background each time :-))

Vinzius
I am kind of lost here :-) In fact, I will not draw the background, let's say it's a gauge image I already have as a .png I only need to draw the indicator that should move around the fixed gauge. Do you mean I need to use 2 views ? The one for the indicator on top of the one with the fixed background (the gauge image) ? thanks for your help
Luc
With coregraphic when you draw in drawRect Method (of UIView), you will overwrite on the previous draw. So if you just draw the indicator, you need to draw again the background (gauge). But to draw one time the gauge png file, you could have one UIImageView (wich contains the png) and one subclass UIView (which draw the indicator) ;-)
Vinzius
A: 

Luc,

Your approach should work fine. Create a custom UIView and override -drawRect: to first draw the background PNG of the gauge, then draw the indicators.

- (void) drawRect: (CGRect) rect {
    \\ draw the gauge PNG into the view bounds
    ...;

    \\ Now use Quartz to draw the indicators
    ...; 
}
Bill Garrison