SIcon_button.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // SIcon_button.m
  3. // LN_School
  4. //
  5. // Created by apple on 2017/4/7.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "SIcon_button.h"
  9. @implementation SIcon_button
  10. -(instancetype)initWithFrame:(CGRect)frame {
  11. self = [super initWithFrame:frame];
  12. if (self) {
  13. self.backgroundColor = [UIColor whiteColor];
  14. self.titleLabel.textAlignment = NSTextAlignmentCenter;
  15. self.imageView.contentMode = UIViewContentModeScaleAspectFill;
  16. self.imageView.layer.masksToBounds = YES;
  17. CGFloat wid = frame.size.width;
  18. _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, wid / 5.0, wid, wid * 4 / 10.0)];
  19. _contentLabel.backgroundColor = [UIColor clearColor];
  20. [_contentLabel setTextAlignment:NSTextAlignmentCenter];
  21. [self addSubview:_contentLabel];
  22. }
  23. return self;
  24. }
  25. -(CGRect)imageRectForContentRect:(CGRect)contentRect
  26. {
  27. CGFloat wid = self.frame.size.width;
  28. return CGRectMake(wid * 3 / 10.0, wid / 5.0, wid * 4 / 10.0, wid * 4 / 10.0);
  29. }
  30. -(CGRect)titleRectForContentRect:(CGRect)contentRect
  31. {
  32. CGFloat wid = self.frame.size.width;
  33. return CGRectMake(0, wid * 6 / 10.0, wid, wid * 3 / 10.0);
  34. }
  35. /*
  36. // Only override drawRect: if you perform custom drawing.
  37. // An empty implementation adversely affects performance during animation.
  38. - (void)drawRect:(CGRect)rect {
  39. // Drawing code
  40. }
  41. */
  42. @end