开发者

convert integer into image value on iPhone

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

eg. show int 123 by using images 1.png, 2.png an开发者_运维技巧d 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?


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜