tags:

views:

50

answers:

1

Ok I am trying to show a number using a series of Images.

eg. show int 123 by using images 1.png, 2.png and 3.png

can someone tell me how can this be done using on iPhone? There are few apps that display time using dotted numbers etc.

OR should i embed a font to display the number in fancy way?

+4  A: 

You can do this very easily. Go digit by digit, creating a UIImage from the digit's png and add it to your view. Move the origin to the left/right by the width of the image and continue with the next digit.

int myValue = 123;
int digit;
CGPoint origin = CGPointMake(100, 0);
while(myValue > 0) {
    digit = myValue % 10;
    myValue /= 10;
    UIImage *myDigitImg = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png",digit]];
    UIImageView *digitView = [[UIImageView alloc] initWithImage:myDigitImage];
    digitView.bounds = CGRectMake(origin.x, origin.y, myDigitImg.size.x, myDigitImg.size.y);
    [myView addSubview:digitView];
    [digitView release];
    origin.x -= myDigitImg.size.x;
}
David Kanarek
Thanks David. That is simply awesome!
John Stewart