#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
时间: 2024-10-11 06:07:29