KKToolBarItem.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // KKToolBarItem.m
  3. // WWImageEdit
  4. //
  5. // Created by 邬维 on 2017/1/3.
  6. // Copyright © 2017年 kook. All rights reserved.
  7. //
  8. #import "KKToolBarItem.h"
  9. #import "UIView+Frame.h"
  10. #define ICON_SIZE 24
  11. @implementation KKToolBarItem
  12. - (instancetype)initWithFrame:(CGRect)frame
  13. {
  14. self = [super initWithFrame:frame];
  15. if (self) {
  16. CGFloat W = frame.size.width;
  17. _iconView = [[UIImageView alloc] initWithFrame:CGRectMake((W-ICON_SIZE)*0.5, 4, ICON_SIZE, ICON_SIZE)];
  18. _iconView.clipsToBounds = YES;
  19. _iconView.layer.cornerRadius = 5;
  20. _iconView.contentMode = UIViewContentModeScaleAspectFill;
  21. [self addSubview:_iconView];
  22. _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _iconView.bottom+2, W, 15)];
  23. _titleLabel.backgroundColor = [UIColor clearColor];
  24. _titleLabel.textColor = [UIColor whiteColor];
  25. _titleLabel.font = [UIFont systemFontOfSize:11];
  26. _titleLabel.textAlignment = NSTextAlignmentCenter;
  27. [self addSubview:_titleLabel];
  28. }
  29. return self;
  30. }
  31. - (instancetype)initWithFrame:(CGRect)frame target:(id)target action:(SEL)action toolInfo:(KKImageToolInfo*)toolInfo
  32. {
  33. self = [self initWithFrame:frame];
  34. if(self){
  35. UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:target action:action];
  36. [self addGestureRecognizer:gesture];
  37. _imgToolInfo = toolInfo;
  38. _titleLabel.text = toolInfo.title;
  39. _iconView.image = toolInfo.iconImage;
  40. }
  41. return self;
  42. }
  43. - (void)setUserInteractionEnabled:(BOOL)userInteractionEnabled
  44. {
  45. [super setUserInteractionEnabled:userInteractionEnabled];
  46. self.alpha = (userInteractionEnabled) ? 1 : 0.3;
  47. }
  48. - (void)setSelected:(BOOL)selected
  49. {
  50. if(selected != _selected){
  51. _selected = selected;
  52. if(selected){
  53. self.backgroundColor = [UIColor grayColor];
  54. }
  55. else{
  56. self.backgroundColor = [UIColor clearColor];
  57. }
  58. }
  59. }
  60. @end