IOS Make custom button link class

//
//  UICustomButton.h


#import <Foundation/Foundation.h>


@interface UICustomButton : UIButton {
    float inflate;
}
@property float inflate;
-(id) initWithFrame:(CGRect)frame inflateBy: (float) infl;
-(id) initWithFrame:(CGRect)frame normalImage:(UIImage *)nImage highlightedImage:(UIImage *)hImage disabledImage:(UIImage *)dImage;
@end

//
//  UICustomButton.m

#import "UICustomButton.h"


@implementation UICustomButton
-(id) initWithFrame:(CGRect)frame inflateBy: (float) infl
{
    self = [super initWithFrame:frame];
    if (self)
    {
        inflate = infl;
        self.adjustsImageWhenHighlighted = FALSE;
    }
    return self;
}
-(id) initWithFrame:(CGRect)frame normalImage:(UIImage *)nImage highlightedImage:(UIImage *)hImage disabledImage:(UIImage *)dImage
{
    self = [super initWithFrame:frame];
    if (self)
    {
        if (nImage) {
            [self setImage:nImage forState:UIControlStateNormal];
        }
        if (hImage) {
            [self setImage:hImage forState:UIControlStateHighlighted];
        }
        if (dImage) {
            [self setImage:dImage forState:UIControlStateDisabled];
        }
    }
    return self;
}
- (void)setInflate:(float)infl
{
    inflate = infl;
    self.adjustsImageWhenHighlighted = FALSE;
}

- (BOOL) beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
    [super beginTrackingWithTouch:touch withEvent:event];
    self.frame = CGRectMake(self.frame.origin.x - inflate, self.frame.origin.y - inflate, self.frame.size.width + 2*inflate, self.frame.size.height + 2*inflate);
    return TRUE;
}

-(BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
    [super continueTrackingWithTouch:touch withEvent:event];
    [NSThread sleepForTimeInterval:0.5];
    return TRUE;
}

-(void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
    [super endTrackingWithTouch:touch withEvent:event];
    self.frame = CGRectMake(self.frame.origin.x + inflate, self.frame.origin.y + inflate, self.frame.size.width - 2*inflate, self.frame.size.height - 2*inflate);
}
-(void)dealloc
{
    [super dealloc];
}
@end

Comments

Popular posts from this blog

Java : Variables Declaring

Install DNF in RHEL/CentOS 7

SQL Self JOIN