You only need to overwrite the corresponding space. I developed the UIButton control.
. H file, as follows:
# Import
# Import
@ Interface ShadowButton: UIButton
{
UIColor * shadowColor;
}
@ Property (nonatomic, strong) UIColor * shadowColor;
@ End
. M file, as shown below
# Import "ShadowButton. h"
@ Implementation ShadowButton
@ Synthesize shadowColor;
-(Void) setProperty
{
Self. imageEdgeInsets = UIEdgeInsetsMake (0,-1, 3, 2 );
Self. shadowColor = [UIColor grayColor];
}
-(Id) initWithFrame :( CGRect) frame
{
Self = [super initWithFrame: frame];
If (self ){
// Initialization code
}
Return self;
}
-(Id) initWithCoder :( NSCoder *) aDecoder
{
Self = [super initWithCoder: aDecoder];
If (self ){
[Self setProperty];
}
Return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
-(Void) drawRect :( CGRect) rect
{
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext ();
CGRect frame = rect;
UIEdgeInsets insets = self. imageEdgeInsets;
Frame. origin. x + = insets. left;
Frame. origin. y + = insets. top;
Frame. size. width-= (insets. left + insets. right );
Frame. size. height-= (insets. top + insets. bottom );
If (shadowColor ){
CGContextSetShadowWithColor (context, CGSizeMake (insets. right, insets. bottom), 10, [shadowColor CGColor]);
}
UIImage * image = self. imageView. image;
[Image drawInRect: frame];
}
@ End