The shadow of the control appears in iOS code control

Source: Internet
Author: User
Tags uikit

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.