Wednesday, February 25, 2015

Create animation for set of Images

 // The root view of the view controller set in Interface Builder is a UIImageView.
    UIImageView *imageView = (UIImageView *)self.view;
    
    imageView.animationImages = @[
                          [UIImage imageNamed:@"image_animal_1"],
                          [UIImage imageNamed:@"image_animal_2"],
                          [UIImage imageNamed:@"image_animal_3"],
                          [UIImage imageNamed:@"image_animal_4"],
                          [UIImage imageNamed:@"image_animal_5"]
                         ];
    
    // We want the image to be scaled to the correct aspect ratio within imageView's bounds.
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    
    // If the image does not have the same aspect ratio as imageView's bounds, then imageView's backgroundColor will be applied to the "empty" space.
    imageView.backgroundColor = [UIColor whiteColor];
    
    imageView.animationDuration = 5;
    [imageView startAnimating];
    
    imageView.isAccessibilityElement = YES;

    imageView.accessibilityLabel = NSLocalizedString(@"Animated", nil);

ActionSheet using UIAlertController


// Show a dialog with an "Okay" and "Cancel" button.
- (void)showOkayCancelActionSheet:(NSIndexPath *)selectedPath {
    NSString *cancelButtonTitle = NSLocalizedString(@"Cancel", nil);
    NSString *destructiveButtonTitle = NSLocalizedString(@"OK", nil);
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    // Create the actions.
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        NSLog(@"The \"Okay/Cancel\" alert action sheet's cancel action occured.");
    }];
    
    UIAlertAction *destructiveAction = [UIAlertAction actionWithTitle:destructiveButtonTitle style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
        NSLog(@"The \"Okay/Cancel\" alert action sheet's destructive action occured.");
    }];
    
    // Add the actions.
    [alertController addAction:cancelAction];
    [alertController addAction:destructiveAction];
    
    // Configure the alert controller's popover presentation controller if it has one.
    UIPopoverPresentationController *popoverPresentationController = [alertController popoverPresentationController];
    if (popoverPresentationController) {
        UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:selectedPath];
        popoverPresentationController.sourceRect = selectedCell.frame;
        popoverPresentationController.sourceView = self.view;
        popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
    }
    
    [self presentViewController:alertController animated:YES completion:nil];

}



Alert using UIAlertController (TextField and Two buttons)

// Show a text entry alert with two custom buttons.
- (void)showTextEntryAlert {

    NSString *title = NSLocalizedString(@"Short_title", nil);
    NSString *message = NSLocalizedString(@"Message", nil);
    NSString *cancelButtonTitle = NSLocalizedString(@"Cancel", nil);
    NSString *otherButtonTitle = NSLocalizedString(@"OK", nil);
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    // Add the text field for text entry.
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        // If you need to customize the text field, you can do so here.
    }];
    
    // Create the actions.
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        NSLog(@"The \"Text Entry\" alert's cancel action occured.");
    }];
    
    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        NSLog(@"The \"Text Entry\" alert's other action occured.");
    }];
    
    // Add the actions.
    [alertController addAction:cancelAction];
    [alertController addAction:otherAction];
    
    [self presentViewController:alertController animated:YES completion:nil];

}


Create Attribute Text button


- (void)configureAttributedTextSystemButton {
    // Set the button's title for normal state.
    NSDictionary *normalTitleAttributes = @{
               NSForegroundColorAttributeName: [UIColor customBlueColor],
               NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle)
                                        };
    
    NSAttributedString *normalAttributedTitle = [[NSAttributedString alloc]
               initWithString:NSLocalizedString(@"Button", nil)
               attributes:normalTitleAttributes];

    [self.attributedTextButton setAttributedTitle:normalAttributedTitle 
               forState:UIControlStateNormal];
    
    // Set the button's title for highlighted state.
    NSDictionary *highlightedTitleAttributes = @{                                                         
             NSForegroundColorAttributeName : [UIColor customGreenColor],                                                
             NSStrikethroughStyleAttributeName: @(NSUnderlineStyleThick)
                                             };
    
    NSAttributedString *highlightedAttributedTitle = [[NSAttributedString
            alloc] initWithString:NSLocalizedString(@"Button", nil)        
            attributes:highlightedTitleAttributes];

    [self.attributedTextButton setAttributedTitle:highlightedAttributedTitle
            forState:UIControlStateHighlighted];
    
    [self.attributedTextButton addTarget:self   
            action:@selector(buttonClicked:) 
            forControlEvents:UIControlEventTouchUpInside];

}