Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  2. static NSString *CellIdentifier = @"Answer";
  3. AnswerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  4.  
  5. // Configure the cell button
  6. cell.answerButton.buttonColor = [UIColor belizeHoleColor];
  7. cell.answerButton.shadowColor = [UIColor wetAsphaltColor];
  8. cell.answerButton.shadowHeight = 3.0f;
  9.  
  10. //Set the tag and selector for the specific button
  11. cell.answerButton.tag = indexPath.row;
  12. [cell.answerButton addTarget:self action:@selector(submitAnswer:) forControlEvents:UIControlEventTouchDown];
  13. cell.answerButton.cornerRadius = 6.0f;
  14. [cell.answerButton setTitleColor:[UIColor cloudsColor] forState:UIControlStateNormal];
  15. [cell.answerButton setTitleColor:[UIColor cloudsColor] forState:UIControlStateHighlighted];
  16.  
  17. cell.answerButton.tag = indexPath.row;
  18.  
  19. tableView.separatorColor = [UIColor clearColor];
  20.  
  21. cell.answerButton.layer.anchorPoint = CGPointMake(0.58f, 1.0f);
  22.  
  23. //Cell Animation
  24. cell.answerButton.alpha = 0.0;
  25. CGRect newFrame = CGRectMake(self.view.frame.size.width, cell.frame.size.height, cell.frame.size.width, cell.frame.size.height);
  26. cell.answerButton.frame = newFrame;
  27. [UIView animateWithDuration:0.9
  28. delay: 0.0
  29. options:UIViewAnimationOptionCurveEaseOut
  30. animations:^{
  31. cell.answerButton.alpha = 1.0f;
  32. CGRect newFrame = CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height);
  33. cell.answerButton.frame = newFrame;
  34. }
  35. completion: ^(BOOL finished) {
  36. }];
  37.  
  38. if (indexPath.row == self.correctAnswerIndex) {
  39. //Set up cell
  40. [cell configureFlatCellWithColor:[UIColor clearColor] selectedColor:[UIColor clearColor] roundingCorners:UIRectCornerAllCorners];
  41.  
  42. cell.cornerRadius = 5.0f;
  43. cell.separatorHeight = 2.0f;
  44.  
  45. //Set it so that if the string is too long there is a line break
  46. cell.answerButton.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
  47. cell.answerButton.titleLabel.numberOfLines = 0;
  48.  
  49. //Set the text alignment to center
  50. cell.answerButton.titleLabel.textAlignment = NSTextAlignmentCenter;
  51.  
  52. //Set the text of the correct answer cell
  53. [cell.answerButton setTitle:capitalName forState:UIControlStateNormal];
  54. }else{
  55. //Set up cell
  56. [cell configureFlatCellWithColor:[UIColor clearColor] selectedColor:[UIColor clearColor] roundingCorners:UIRectCornerAllCorners];
  57.  
  58. cell.cornerRadius = 5.0f;
  59. cell.separatorHeight = 2.0f;
  60.  
  61. //Set it so that if the string is too long there is a line break
  62. cell.answerButton.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
  63. cell.answerButton.titleLabel.numberOfLines = 0;
  64.  
  65. //Set the text alignment to center
  66. cell.answerButton.titleLabel.textAlignment = NSTextAlignmentCenter;
  67.  
  68. //Set the text of the incorrect answer cell
  69. if (self.threeIncorrectAnswers.count != 0) {
  70. //Generate a random number based on the indexes of the array
  71. int randomIndex = arc4random() % self.threeIncorrectAnswers.count;
  72. [cell.answerButton setTitle:[self.threeIncorrectAnswers objectAtIndex:randomIndex] forState:UIControlStateNormal];
  73.  
  74. //Remove the incorrect answer
  75. [self.threeIncorrectAnswers removeObjectAtIndex:randomIndex];
  76. }
  77. }
  78.  
  79. //Entering Animation
  80. cell.answerAnimationView.duration = 0.5;
  81. cell.answerAnimationView.delay = 0.0;
  82. cell.answerAnimationView.type = CSAnimationTypeFadeInLeft;
  83.  
  84. // Kick start the animation immediately
  85. [cell startCanvasAnimation];
  86.  
  87. tableView.userInteractionEnabled = YES;
  88. cell.userInteractionEnabled = YES;
  89. cell.answerAnimationView.userInteractionEnabled = YES;
  90. cell.answerButton.userInteractionEnabled = YES;
  91.  
  92. return cell;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement