CustomButton.m 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // CustomButton.m
  3. // IBOSS
  4. //
  5. // Created by ssl on 2017/7/13.
  6. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. #import "CustomButton.h"
  9. @interface CustomButton (){
  10. CGFloat _width;
  11. CGFloat _height ;
  12. }
  13. @end
  14. @implementation CustomButton
  15. - (instancetype)initWithFrame:(CGRect)frame andImage:(UIImage *) img addText:(NSString *) string addImageWidth:(CGFloat) width addImageHeight:(CGFloat) height{
  16. self = [super initWithFrame:frame];
  17. _width = width;
  18. _height = height;
  19. _img = img;
  20. _string = string;
  21. return self;
  22. }
  23. - (void)layoutSubviews{
  24. UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(10, (self.frame.size.height-10)/2, _width, _height)];
  25. [img setImage:_img];
  26. [self addSubview:img];
  27. UILabel *text = [[UILabel alloc] initWithFrame:CGRectMake(22, (self.frame.size.height-10)/2, self.frame.size.width-25, 14)];
  28. text.text = _string;
  29. text.textAlignment = NSTextAlignmentCenter;
  30. text.font = [UIFont systemFontOfSize:14];
  31. [self addSubview:text];
  32. }
  33. @end