// // CustomButton.m // IBOSS // // Created by ssl on 2017/7/13. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved. // #import "CustomButton.h" @interface CustomButton (){ CGFloat _width; CGFloat _height ; } @end @implementation CustomButton - (instancetype)initWithFrame:(CGRect)frame andImage:(UIImage *) img addText:(NSString *) string addImageWidth:(CGFloat) width addImageHeight:(CGFloat) height{ self = [super initWithFrame:frame]; _width = width; _height = height; _img = img; _string = string; return self; } - (void)layoutSubviews{ UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(10, (self.frame.size.height-10)/2, _width, _height)]; [img setImage:_img]; [self addSubview:img]; UILabel *text = [[UILabel alloc] initWithFrame:CGRectMake(22, (self.frame.size.height-10)/2, self.frame.size.width-25, 14)]; text.text = _string; text.textAlignment = NSTextAlignmentCenter; text.font = [UIFont systemFontOfSize:14]; [self addSubview:text]; } @end