views:

1014

answers:

2

I've created a NIB file with some button controls on it, and as a background it has an ImageView which contains a PNG file loaded from my project.

What I want to do is to draw on top of the ImageView - imagine that my UI is a clockface and I want to draw the hands of the clock on top of the background image.

Is it the correct approach to try to subclass the UIImageView and use its DrawRect as when I use the DrawRect of the default view I don't see anything on the screen?

I'm a little lost as I'm finding this particular bit of the documentation hard to follow. Thanks.

+4  A: 

Create a new custom UIView (e.g. named HandsView) that sits on top of your background view (by adding it as a subview of the UIImageView). In the custom view, you can use the drawRect method. Make sure, you clear the context to transparent, so that the background image can be seen below the HandsView.

If you just want to draw turning hands, you can also try to use two fixed UIImageViews with the images of the hands and use the transform property to apply a rotation.

Nikolai Ruhe
What he said. Seriously, this is what you want to do. UIKit uses the "painter's model" so you can always layer more UIViews and CAlayers.
Corey Floyd
I created a view in Interface Builder and associated it with a class inheriting from UIView. If I set the alpha value so that it's transparent I can't see the UIImage that I subsequently add to the view as it's also transparent.Should I be setting the transparency differently or is there something I need to set in the UIImage?
Neosionnach
Whoops, I'm so sorry, I figured it out.I didn't need to change the transparency in IB, I just needed to add the following code inside the UIView class I made.- (void) awakeFromNib { self.backgroundColor = [UIColor clearColor]; }Then, the view I added isn't visible but the UIImage I subsequently added is! Thanks for your help.
Neosionnach
A: 

how do i create a opengles 3d cube over the same view?

can i have a nib view loaded and get 3d cube of opengl rotating within the same view?

say i want to have a 3d cube rotating over addMusic sample code by apple. in the screen with 'your application here' message.... please show me a way, a sample code tweak of the same will be great!

thanks, don

don