Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top