Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- static NSString *CellIdentifier = @"Answer";
- AnswerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- // Configure the cell button
- cell.answerButton.buttonColor = [UIColor belizeHoleColor];
- cell.answerButton.shadowColor = [UIColor wetAsphaltColor];
- cell.answerButton.shadowHeight = 3.0f;
- //Set the tag and selector for the specific button
- cell.answerButton.tag = indexPath.row;
- [cell.answerButton addTarget:self action:@selector(submitAnswer:) forControlEvents:UIControlEventTouchDown];
- cell.answerButton.cornerRadius = 6.0f;
- [cell.answerButton setTitleColor:[UIColor cloudsColor] forState:UIControlStateNormal];
- [cell.answerButton setTitleColor:[UIColor cloudsColor] forState:UIControlStateHighlighted];
- cell.answerButton.tag = indexPath.row;
- tableView.separatorColor = [UIColor clearColor];
- cell.answerButton.layer.anchorPoint = CGPointMake(0.58f, 1.0f);
- //Cell Animation
- cell.answerButton.alpha = 0.0;
- CGRect newFrame = CGRectMake(self.view.frame.size.width, cell.frame.size.height, cell.frame.size.width, cell.frame.size.height);
- cell.answerButton.frame = newFrame;
- [UIView animateWithDuration:0.9
- delay: 0.0
- options:UIViewAnimationOptionCurveEaseOut
- animations:^{
- cell.answerButton.alpha = 1.0f;
- CGRect newFrame = CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height);
- cell.answerButton.frame = newFrame;
- }
- completion: ^(BOOL finished) {
- }];
- if (indexPath.row == self.correctAnswerIndex) {
- //Set up cell
- [cell configureFlatCellWithColor:[UIColor clearColor] selectedColor:[UIColor clearColor] roundingCorners:UIRectCornerAllCorners];
- cell.cornerRadius = 5.0f;
- cell.separatorHeight = 2.0f;
- //Set it so that if the string is too long there is a line break
- cell.answerButton.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
- cell.answerButton.titleLabel.numberOfLines = 0;
- //Set the text alignment to center
- cell.answerButton.titleLabel.textAlignment = NSTextAlignmentCenter;
- //Set the text of the correct answer cell
- [cell.answerButton setTitle:capitalName forState:UIControlStateNormal];
- }else{
- //Set up cell
- [cell configureFlatCellWithColor:[UIColor clearColor] selectedColor:[UIColor clearColor] roundingCorners:UIRectCornerAllCorners];
- cell.cornerRadius = 5.0f;
- cell.separatorHeight = 2.0f;
- //Set it so that if the string is too long there is a line break
- cell.answerButton.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
- cell.answerButton.titleLabel.numberOfLines = 0;
- //Set the text alignment to center
- cell.answerButton.titleLabel.textAlignment = NSTextAlignmentCenter;
- //Set the text of the incorrect answer cell
- if (self.threeIncorrectAnswers.count != 0) {
- //Generate a random number based on the indexes of the array
- int randomIndex = arc4random() % self.threeIncorrectAnswers.count;
- [cell.answerButton setTitle:[self.threeIncorrectAnswers objectAtIndex:randomIndex] forState:UIControlStateNormal];
- //Remove the incorrect answer
- [self.threeIncorrectAnswers removeObjectAtIndex:randomIndex];
- }
- }
- //Entering Animation
- cell.answerAnimationView.duration = 0.5;
- cell.answerAnimationView.delay = 0.0;
- cell.answerAnimationView.type = CSAnimationTypeFadeInLeft;
- // Kick start the animation immediately
- [cell startCanvasAnimation];
- tableView.userInteractionEnabled = YES;
- cell.userInteractionEnabled = YES;
- cell.answerAnimationView.userInteractionEnabled = YES;
- cell.answerButton.userInteractionEnabled = YES;
- return cell;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement