AvePurchaseButton 1.0.6

AvePurchaseButton 1.0.6

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Feb 2017

Maintained by Andreas Verhoeven.




Drop In App Store Styled Purchase Button, with proper animations. Title configurable in Interface Builder.

Animations

A gif-movie showing how the button animates from normal to confirmation to in-progress state: Movie

Screenshot

A screenshot showing the different states of the button: Screenshot

How to use

Create an instance of AvePurchaseButton. Set the normalTitle, confirmationTitle and handle UIControlEventTouchUpInside. To change states, use -[AvePurchaseButton setButtonState:animated:].

Example usage:

- (void)addPurchaseButton {
  AvePurchaseButton* button = [[AvePurchaseButton alloc] initWithFrame:CGRectZero];
    [button addTarget:self action:@selector(purchaseButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
    button.buttonState = AvePurchaseButtonStateNormal;
    button.normalTitle = @"$ 2.99";
    button.confirmationTitle = @"BUY";
    [button sizeToFit];
    [self.view addSubview:button];
}

- (void)purchaseButtonTapped:(AvePurchaseButton*)button {
    switch(button.buttonState) {
        case AvePurchaseButtonStateNormal:
            [button setButtonState:AvePurchaseButtonStateConfirmation animated:YES];
            break;

        case AvePurchaseButtonStateConfirmation:
            // start the purchasing progress here, when done, go back to 
            // AvePurchaseButtonStateProgress
            [button setButtonState:AvePurchaseButtonStateProgress animated:YES];

            [self startPurchaseWithCompletionHandler:^{
               [button setButtonState:AvePurchaseButtonStateNormal animated:YES];
            }];
            break;

        case AvePurchaseButtonStateProgress:
            break;
    }
}