自定义Button 图片在上面文字在下面

#import "buttonCustom.h"
#define KimageW 30
#define KtitleH 21
#define Kpadding 10
@interface buttonCustom()

@end

@implementation buttonCustom

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return self;
}

//set title
- (void)setTitle:(NSString *)title forState:(UIControlState)state{
    [super setTitle:title forState:state];
   
}

//set image
- (void)setImage:(UIImage *)image forState:(UIControlState)state
{
    [super setImage:image forState:state];
    
}


//custom title rect
- (CGRect)titleRectForContentRect:(CGRect)contentRect{
    return CGRectMake(0 , Kpadding *2 , self.bounds.size.width, 21 );
}

//custom image rect
- (CGRect)imageRectForContentRect:(CGRect)contentRect{
    return CGRectMake(0 , Kpadding ,self.bounds.size.width , KimageW);
}
@end

 

posted @ 2016-01-06 10:26  Mantis-man  阅读(771)  评论(0编辑  收藏  举报