//
//  VFYButton.m
//  Verif-y
//
//  Created by MTN on 05/11/20.
//


#import "VFYButton.h"

#define pressDuration 0.1

@implementation VFYButton

-(void)animateOnPress:(BOOL)animate
          borderColor:(UIColor*) BorderColor
          backGroundColor:(UIColor*) BackGroundColor
            textColor:(UIColor*) TextColor  {
    if(animate){
        [self addTarget:self action:@selector(pressAnimation) forControlEvents:UIControlEventTouchDown];
        [self addTarget:self action:@selector(unpressAnimation) forControlEvents:UIControlEventTouchUpInside];
    }
    if (BorderColor != nil) {
        UIColor *col = BorderColor;
        self.layer.borderWidth = 2.0f;
        self.layer.borderColor = [col CGColor];
        self.layer.cornerRadius = 5.0f;
        self.clipsToBounds = true;
    }
    if (BackGroundColor != nil) {
        [self setBackgroundColor:BackGroundColor];
    }
    if(TextColor != nil){
        [self setTitleColor:TextColor forState:UIControlStateNormal];
    }
}

-(void)pressAnimation{
    [UIView animateWithDuration:pressDuration animations:^{
        self.transform = CGAffineTransformMakeScale(0.85, 0.85);
    }];
}

-(void)unpressAnimation{
    [UIView animateWithDuration:pressDuration animations:^{
        self.transform = CGAffineTransformMakeScale(1, 1);
    }];
}

@end
