Showing posts with label xcode. Show all posts
Showing posts with label xcode. Show all posts

Friday, June 10, 2011

Converting NSString to int and Vice Versa

int to NSString

The following example displays an integer's value as a text label:
currentScoreLabel.text = [NSString stringWithFormat:@"%d", currentScore];


NSString to int

The following example displays a text value as a integer:
int currentScore=[currentScoreLabel.text intValue];

Animate series of images

As iPhone does not supports gif files so heres the way to animate series of images

NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"image1.png"],
[UIImage imageNamed:@"image2.png"],
[UIImage imageNamed:@"image3.png"],
[UIImage imageNamed:@"image4.gif"],
nil];

UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:[self bounds]];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 0.25; // seconds
myAnimatedView.animationRepeatCount = 0; // 0 = loops forever
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];
[myAnimatedView release];

For Getting Log

In Xcode, click Run > Console to see NSLog statements.
NSLog(@"log: %@ ", myString);
NSLog(@"log: %f ", myFloat);
NSLog(@"log: %i ", myInt);

Followers