MMRichEditAccessoryView.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // MMRichEditAccessoryView.m
  3. // RichTextEditDemo
  4. //
  5. // Created by aron on 2017/7/21.
  6. // Copyright © 2017年 aron. All rights reserved.
  7. //
  8. #import "MMRichEditAccessoryView.h"
  9. #import <Masonry.h>
  10. #import "UtilMacro.h"
  11. @interface MMRichEditAccessoryView ()
  12. @property (nonatomic, strong) UIImageView* kbImageIcon;
  13. @property (nonatomic, strong) UIImageView* picImageIcon;
  14. @end
  15. @implementation MMRichEditAccessoryView
  16. - (instancetype)init {
  17. if (self = [super init]) {
  18. self.clipsToBounds = YES;
  19. self.backgroundColor = [UIColor whiteColor];
  20. [self setupUI];
  21. }
  22. return self;
  23. }
  24. - (void)setupUI {
  25. [self addSubview:self.kbImageIcon];
  26. [self addSubview:self.picImageIcon];
  27. [self.kbImageIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.left.equalTo(self).offset(convertLength(20));
  29. make.centerY.equalTo(self.mas_centerY);
  30. }];
  31. [self.picImageIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.right.equalTo(self).offset(-convertLength(20));
  33. make.centerY.equalTo(self.mas_centerY);
  34. }];
  35. }
  36. - (UIImageView *)kbImageIcon {
  37. if (!_kbImageIcon) {
  38. _kbImageIcon = [UIImageView new];
  39. _kbImageIcon.contentMode = UIViewContentModeScaleAspectFit;
  40. _kbImageIcon.image = [UIImage imageNamed:@"ABC_icon"];
  41. _kbImageIcon.userInteractionEnabled = YES;
  42. [_kbImageIcon addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onKbImageIconTap:)]];
  43. }
  44. return _kbImageIcon;
  45. }
  46. - (UIImageView *)picImageIcon {
  47. if (!_picImageIcon) {
  48. _picImageIcon = [UIImageView new];
  49. _picImageIcon.contentMode = UIViewContentModeScaleAspectFit;
  50. _picImageIcon.image = [UIImage imageNamed:@"img_icon"];
  51. _picImageIcon.userInteractionEnabled = YES;
  52. [_picImageIcon addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onPicImageIconTap:)]];
  53. }
  54. return _picImageIcon;
  55. }
  56. - (void)drawRect:(CGRect)rect {
  57. [super drawRect:rect];
  58. // 绘制顶部分割线
  59. UIBezierPath *path = [UIBezierPath bezierPath];
  60. [path moveToPoint:CGPointMake(0, 0.5f)];
  61. [path addLineToPoint:CGPointMake(CGRectGetMaxX(rect), 0.5f)];
  62. [path moveToPoint:CGPointMake(0, CGRectGetMaxY(rect) - 0.5f)];
  63. [path addLineToPoint:CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect) - 0.5f)];
  64. path.lineWidth = 1.f;
  65. [[UIColor colorWithWhite:0.9 alpha:1.f] setStroke];
  66. [path stroke];
  67. }
  68. #pragma mark - ......::::::: ui action :::::::......
  69. - (void)onKbImageIconTap:(UITapGestureRecognizer*)gesture {
  70. if ([self.delegate respondsToSelector:@selector(mm_didKeyboardTapInaccessoryView:)]) {
  71. [self.delegate mm_didKeyboardTapInaccessoryView:self];
  72. }
  73. }
  74. - (void)onPicImageIconTap:(UITapGestureRecognizer*)gesture {
  75. if ([self.delegate respondsToSelector:@selector(mm_didImageTapInaccessoryView:)]) {
  76. [self.delegate mm_didImageTapInaccessoryView:self];
  77. }
  78. }
  79. #pragma mark - ......::::::: public :::::::......
  80. - (void)setHiddenActionButtons:(BOOL)hideActionButtons {
  81. self.picImageIcon.hidden = hideActionButtons;
  82. }
  83. @end