Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. one = [UIImage imageNamed:@"1.png"]; //Image for the number 1
  2. two = [UIImage imageNamed:@"2.png"]; //Image for the number 2
  3. three = [UIImage imageNamed:@"3.png"]; //Image for the number 3
  4.  
  5. NSString *score = "132"; //This is the score the user got
  6.  
  7. if ([score rangeOfString:@"1"].location == NSFound) {
  8. imagescore = one; //If the score contains one, the image adds the image 1
  9. }
  10. if ([score rangeOfString:@"2"].location == NSFound) {
  11. imagescore += two; //If the score contains two, the image adds the image 2
  12. }
  13. if ([score rangeOfString:@"3"].location == NSFound) {
  14. imagescore +=three; //If the score contains two, the image adds the image 3
  15. }
  16. imageView.image = imagescore; //Would change the image to the images of the score in order
  17.  
  18. -(void)calculateScore{
  19. NSString *score = @"132";
  20.  
  21. UIImage *scroreImage = [UIImage new];
  22. // NSMutableArray *images = [[NSMutableArray alloc]initWithCapacity:score.length];
  23.  
  24. for (int i = 0; i < score.length; i++) {
  25. // imageName will be @"1", then @"3" and @"2"
  26. NSString *imageName = [[score substringToIndex:i] substringToIndex:1];
  27.  
  28. // add extension
  29. imageName = [imageName stringByAppendingString:@".png"];
  30.  
  31. UIImage *image = [UIImage imageNamed:imageName];
  32.  
  33. //[images addObject:image];
  34. scroreImage = [self concateImageOne:scroreImage withImageTwo:image]
  35. }
  36. }
  37.  
  38. -(UIImage*)concateImageOne:(UIImage*)image1 withImageTwo:(UIImage*)image2
  39. {
  40. ///Merge images together
  41. }
  42.  
  43. -(UIImage*)concateImageOne:(UIImage*)image1 withImageTwo:(UIImage*)image2
  44. {
  45. CGSize size = CGSizeMake(image1.size.width, image1.size.height + image2.size.height);
  46. UIGraphicsBeginImageContext(size);
  47.  
  48. [image1 drawInRect:CGRectMake(0,0,size.width, image1.size.height)];
  49. [image2 drawInRect:CGRectMake(0,image1.size.height,size.width, image2.size.height)];
  50.  
  51. UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
  52.  
  53. UIGraphicsEndImageContext();
  54. return finalImage;
  55. }
  56.  
  57. if ([score rangeOfString:@"1"].location == NSFound) {
  58. if (!imagescore)
  59. imagescore = one; //If the score contains one, the image adds the image 1
  60. else
  61. imagescore = [self concateImageOne:imagescore withImageTwo:one]
  62. }
  63.  
  64. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imagescore.size.width, imagescore.size.height)];
  65. imageView.image = imagescore;
  66.  
  67. - (NSArray *)imageFromString:(NSString *)scoreString
  68. {
  69. NSMutableArray *scoreImages = [[NSMutableArray alloc] init];
  70. for (int i = 0; i < scoreString.length; i++) {
  71. NSString *imageName = [NSString stringWithFormat:@"%c.png", [scoreString characterAtIndex:i]];
  72. UIImage *image = [UIImage imageNamed:imageName];
  73. [scoreImages addObject:image];
  74. }
  75. return scoreImages;
  76. }
  77.  
  78. -(void)calculateScore {
  79. int hundred = self.score / 100;
  80. int ten = self.score / 10;
  81. int remainder = self.score % 10;
  82.  
  83. NSString *hundredString = [NSString stringWithFormat:@"number_%d.png", hundred];
  84. NSString *tenString = [NSString stringWithFormat:@"number_%d.png", ten];
  85. NSString *remainderString = [NSString stringWithFormat:@"number_%d.png", remainder];
  86.  
  87. self.hundredImageView.image = [UIImage imageNamed:hundredString];
  88. self.tenImageView.image = [UIImage imageNamed:tenString];
  89. self.remainderImageView.image = [UIImage imageNamed:remainderString];
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement