Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- one = [UIImage imageNamed:@"1.png"]; //Image for the number 1
- two = [UIImage imageNamed:@"2.png"]; //Image for the number 2
- three = [UIImage imageNamed:@"3.png"]; //Image for the number 3
- NSString *score = "132"; //This is the score the user got
- if ([score rangeOfString:@"1"].location == NSFound) {
- imagescore = one; //If the score contains one, the image adds the image 1
- }
- if ([score rangeOfString:@"2"].location == NSFound) {
- imagescore += two; //If the score contains two, the image adds the image 2
- }
- if ([score rangeOfString:@"3"].location == NSFound) {
- imagescore +=three; //If the score contains two, the image adds the image 3
- }
- imageView.image = imagescore; //Would change the image to the images of the score in order
- -(void)calculateScore{
- NSString *score = @"132";
- UIImage *scroreImage = [UIImage new];
- // NSMutableArray *images = [[NSMutableArray alloc]initWithCapacity:score.length];
- for (int i = 0; i < score.length; i++) {
- // imageName will be @"1", then @"3" and @"2"
- NSString *imageName = [[score substringToIndex:i] substringToIndex:1];
- // add extension
- imageName = [imageName stringByAppendingString:@".png"];
- UIImage *image = [UIImage imageNamed:imageName];
- //[images addObject:image];
- scroreImage = [self concateImageOne:scroreImage withImageTwo:image]
- }
- }
- -(UIImage*)concateImageOne:(UIImage*)image1 withImageTwo:(UIImage*)image2
- {
- ///Merge images together
- }
- -(UIImage*)concateImageOne:(UIImage*)image1 withImageTwo:(UIImage*)image2
- {
- CGSize size = CGSizeMake(image1.size.width, image1.size.height + image2.size.height);
- UIGraphicsBeginImageContext(size);
- [image1 drawInRect:CGRectMake(0,0,size.width, image1.size.height)];
- [image2 drawInRect:CGRectMake(0,image1.size.height,size.width, image2.size.height)];
- UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- return finalImage;
- }
- if ([score rangeOfString:@"1"].location == NSFound) {
- if (!imagescore)
- imagescore = one; //If the score contains one, the image adds the image 1
- else
- imagescore = [self concateImageOne:imagescore withImageTwo:one]
- }
- UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imagescore.size.width, imagescore.size.height)];
- imageView.image = imagescore;
- - (NSArray *)imageFromString:(NSString *)scoreString
- {
- NSMutableArray *scoreImages = [[NSMutableArray alloc] init];
- for (int i = 0; i < scoreString.length; i++) {
- NSString *imageName = [NSString stringWithFormat:@"%c.png", [scoreString characterAtIndex:i]];
- UIImage *image = [UIImage imageNamed:imageName];
- [scoreImages addObject:image];
- }
- return scoreImages;
- }
- -(void)calculateScore {
- int hundred = self.score / 100;
- int ten = self.score / 10;
- int remainder = self.score % 10;
- NSString *hundredString = [NSString stringWithFormat:@"number_%d.png", hundred];
- NSString *tenString = [NSString stringWithFormat:@"number_%d.png", ten];
- NSString *remainderString = [NSString stringWithFormat:@"number_%d.png", remainder];
- self.hundredImageView.image = [UIImage imageNamed:hundredString];
- self.tenImageView.image = [UIImage imageNamed:tenString];
- self.remainderImageView.image = [UIImage imageNamed:remainderString];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement