views:

36

answers:

1

I'm developing a custom UIView component. It's a simple little stopwatch, with PNG graphics for all the digits. There are lots of tutorials around, so I'm figuring most of it out on my own. But I have two questions:

First of all, the component will always have a particular size (141 x 32), but I don't know how to specify that from within the UIView subclass. The "frame" property wants me to define not only the width and height, but also the x and y position. Of course, I won't know the position until the component is placed into some parent view. How do I do that?

Secondly, for drawing the all the digit images within the component, I don't know whether I should create UIImageView objects and lay them out as children, or whether I should just draw the images directly within the view's drawRect method. The stopwatch displays hour:minute:second.tenth data, so there will be at least one image updated ten times per second, and one image updated every second. I could easily reassign the "image" property of the UIImageView, or I could just redraw everything using the UIImages directly.

What considerations should I take into account when deciding which drawing strategy to use? Are there some cases where one choice is better than the other?

EDIT:

I should also mention that I'm trying to develop this component entirely without XIB files, since I'm trying to get a better understanding of the underlying mechanics of custom component development.

A: 

Just put 0,0 for x,y position in the frame initially. The origin will be set to an actual position when you add it to your view.

progrmr