Only need to put the corresponding space, to rewrite. I developed the main target for UIButton this control
. h files, as follows:
#import
#import
@interface Shadowbutton:uibutton
{
Uicolor *shadowcolor;
}
@property (nonatomic, strong) Uicolor *shadowcolor;
@end
. m files, as follows
#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.
-(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), [Shadowcolor Cgcolor]);
}
UIImage *image = self.imageView.image;
[Image Drawinrect:frame];
}
@end