IconButton.m 898 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //
  2. // IconButton.m
  3. // BuguLive
  4. //
  5. // Created by 朱庆彬 on 2017/8/15.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "IconButton.h"
  9. #define IMG_H_W 20.0f
  10. @implementation IconButton
  11. - (instancetype)initWithFrame:(CGRect)frame
  12. {
  13. if (self = [super initWithFrame:frame])
  14. {
  15. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(self.bounds.size.width - 0.5, 0, 0.5, self.bounds.size.height)];
  16. line.backgroundColor = [UIColor lightGrayColor];
  17. [self addSubview:line];
  18. }
  19. return self;
  20. }
  21. - (CGRect)imageRectForContentRect:(CGRect)contentRect
  22. {
  23. CGRect rect = [super imageRectForContentRect:contentRect];
  24. rect.size.height = rect.size.width = IMG_H_W;
  25. CGFloat w = self.bounds.size.width;
  26. CGFloat h = self.bounds.size.height;
  27. rect.origin = CGPointMake((w - IMG_H_W) / 2.0f, (h - IMG_H_W) / 2.0f);
  28. return rect;
  29. }
  30. @end