博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

自定义 UIButotn

Posted on 2012-01-16 17:56  星尘的天空  阅读(340)  评论(0编辑  收藏  举报

全局定制TITextField

参考代码

@interface myButton : UIButton

{

}

//+(id)myButton;

@end

 

@implementation myButton

-(void)awakeFromNib

{

    UIImage* image = [UIImage imageNamed:@"按钮-点击前.png"];

    image = [image stretchableImageWithLeftCapWidth:image.size.width/2.0ftopCapHeight:image.size.height/2.0f];

    [selfsetBackgroundImage:image forState:UIControlStateNormal];

    image = [UIImage imageNamed:@"按钮-点击后.png"];

    image = [image stretchableImageWithLeftCapWidth:image.size.width/2.0f topCapHeight:image.size.height/2.0f];    

    [selfsetBackgroundImage:image forState:UIControlStateHighlighted];        

    [self.titleLabelsetFont:[UIFontsystemFontOfSize:12]];

    [selfsetTitleShadowColor:[UIColorwhiteColor] forState:UIControlStateNormal];

    [selfsetTitleShadowColor:[UIColorblackColor] forState:UIControlStateHighlighted];

    [selfsetTitleColor:c_btn_grayforState:UIControlStateNormal];

    [selfsetTitleColor:c_whiteforState:UIControlStateHighlighted];

}

 - (id)initWithFrame:(CGRect)frame

{

    self = [superinitWithFrame:frame];

    if (self) {

        UIImage* image = [UIImage imageNamed:@"按钮-点击前.png"];

        image = [image stretchableImageWithLeftCapWidth:image.size.width/2.0f topCapHeight:image.size.height/2.0f];

        [selfsetBackgroundImage:image forState:UIControlStateNormal];

        image = [UIImage imageNamed:@"按钮-点击后.png"];

        image = [image stretchableImageWithLeftCapWidth:image.size.width/2.0f topCapHeight:image.size.height/2.0f];          

        [selfsetBackgroundImage:image forState:UIControlStateHighlighted];        

        [self.titleLabelsetFont:[UIFontsystemFontOfSize:12]];

        [self.titleLabel setShadowColor:[UIColor whiteColor]];        

        [selfsetTitleColor:c_btn_grayforState:UIControlStateNormal];

        [selfsetTitleColor:c_whiteforState:UIControlStateHighlighted]; 

        [selfsetTitleShadowColor:[UIColorwhiteColor] forState:UIControlStateNormal];

        [selfsetTitleShadowColor:[UIColorblackColor] forState:UIControlStateHighlighted];        

    }

    returnself;

}

@end

 

 

THE END !