CPDFInkTopToolBar.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // CPDFFreehandView.m
  3. // ComPDFKit_Tools
  4. //
  5. // Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. #import "CPDFInkTopToolBar.h"
  13. #if __has_include(<ComPDFKit_Tools/ComPDFKit_Tools.h>)
  14. #import <ComPDFKit_Tools/ComPDFKit_Tools.h>
  15. #else
  16. #import "ComPDFKit_Tools.h"
  17. #endif
  18. @interface CPDFInkTopToolBar ()
  19. @end
  20. @implementation CPDFInkTopToolBar
  21. #pragma mark - Initializers
  22. - (instancetype)initWithFrame:(CGRect)frame {
  23. if (self = [super initWithFrame:frame]) {
  24. self.layer.borderColor = [UIColor colorWithRed:170.0/255.0 green:170.0/255.0 blue:170.0/255.0 alpha:1.0].CGColor;
  25. self.layer.borderWidth = 1.0;
  26. self.layer.cornerRadius = 5.0;
  27. CGFloat width = self.bounds.size.width/6;
  28. CGFloat height = self.bounds.size.height;
  29. self.buttonArray = [NSMutableArray array];
  30. UIButton *settingButton = [UIButton buttonWithType:UIButtonTypeCustom];
  31. settingButton.tag = CPDFInkTopToolBarSetting;
  32. settingButton.frame = CGRectMake(0, 0, width, height);
  33. [settingButton setImage:[UIImage imageNamed:@"CPDFInkImageSetting" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  34. [settingButton addTarget:self action:@selector(buttonItemClicked_Switch:) forControlEvents:UIControlEventTouchUpInside];
  35. [self addSubview:settingButton];
  36. [self.buttonArray addObject:settingButton];
  37. UIButton *eraseButton = [UIButton buttonWithType:UIButtonTypeCustom];
  38. eraseButton.tag = CPDFInkTopToolBarErase;
  39. eraseButton.frame = CGRectMake(width, 0, width, height);
  40. [eraseButton setImage:[UIImage imageNamed:@"CPDFInkImageEraer" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  41. [eraseButton addTarget:self action:@selector(buttonItemClicked_Switch:) forControlEvents:UIControlEventTouchUpInside];
  42. [self addSubview:eraseButton];
  43. [self.buttonArray addObject:eraseButton];
  44. UIButton *undoButton = [[UIButton alloc] init];
  45. undoButton.tag = CPDFInkTopToolBarUndo;
  46. undoButton.frame = CGRectMake(width*2, 0, width, height);
  47. [undoButton setImage:[UIImage imageNamed:@"CPDFInkImageUndo" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  48. [undoButton addTarget:self action:@selector(buttonItemClicked_Switch:) forControlEvents:UIControlEventTouchUpInside];
  49. [self addSubview:undoButton];
  50. [self.buttonArray addObject:undoButton];
  51. UIButton *redoButton = [UIButton buttonWithType:UIButtonTypeCustom];
  52. redoButton.tag = CPDFInkTopToolBarRedo;
  53. redoButton.frame = CGRectMake(width*3, 0, width, height);
  54. [redoButton setImage:[UIImage imageNamed:@"CPDFInkImageRedo" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  55. [redoButton addTarget:self action:@selector(buttonItemClicked_Switch:) forControlEvents:UIControlEventTouchUpInside];
  56. [self addSubview:redoButton];
  57. [self.buttonArray addObject:redoButton];
  58. UIButton *clearButton = [UIButton buttonWithType:UIButtonTypeSystem];
  59. clearButton.tag = CPDFInkTopToolBarClear;
  60. clearButton.frame = CGRectMake(4*width, 0, width, height);
  61. [clearButton setTitle:NSLocalizedString(@"Clear", nil) forState:UIControlStateNormal];
  62. [clearButton setTitleColor:[CPDFColorUtils CPageEditToolbarFontColor] forState:UIControlStateNormal];
  63. clearButton.titleLabel.font = [UIFont systemFontOfSize:15.0];
  64. [clearButton addTarget:self action:@selector(buttonItemClicked_Switch:) forControlEvents:UIControlEventTouchUpInside];
  65. [self addSubview:clearButton];
  66. [self.buttonArray addObject:clearButton];
  67. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(4*width, 10, 1, height-20)];
  68. view.backgroundColor = [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.1];
  69. [self addSubview:view];
  70. UIButton *saveButton = [UIButton buttonWithType:UIButtonTypeSystem];
  71. saveButton.tag = CPDFInkTopToolBarSave;
  72. saveButton.frame = CGRectMake(5*width, 0, width, height);
  73. [saveButton setTitle:NSLocalizedString(@"Save", nil) forState:UIControlStateNormal];
  74. [saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
  75. saveButton.titleLabel.font = [UIFont systemFontOfSize:15.0];
  76. [saveButton addTarget:self action:@selector(buttonItemClicked_Switch:) forControlEvents:UIControlEventTouchUpInside];
  77. [self addSubview:saveButton];
  78. [self.buttonArray addObject:saveButton];
  79. self.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  80. }
  81. return self;
  82. }
  83. #pragma mark - Action
  84. - (void)buttonItemClicked_Switch:(UIButton *)button {
  85. for (int j = 0; j < self.buttonArray.count; j++) {
  86. ((UIButton *)self.buttonArray[j]).backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  87. }
  88. ((UIButton *)self.buttonArray[button.tag]).backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  89. switch (button.tag) {
  90. case CPDFInkTopToolBarSetting: {
  91. if (self.delegate && [self.delegate respondsToSelector:@selector(inkTopToolBar:tag:isSelect:)]) {
  92. [self.delegate inkTopToolBar:self tag:(CPDFInkTopToolBarSelect)button.tag isSelect:button.isSelected];
  93. }
  94. }
  95. break;
  96. case CPDFInkTopToolBarErase: {
  97. button.selected = !button.isSelected;
  98. if (!button.selected) {
  99. button.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  100. }
  101. if (self.delegate && [self.delegate respondsToSelector:@selector(inkTopToolBar:tag:isSelect:)]) {
  102. [self.delegate inkTopToolBar:self tag:(CPDFInkTopToolBarSelect)button.tag isSelect:button.isSelected];
  103. }
  104. }
  105. break;
  106. case CPDFInkTopToolBarUndo: {
  107. if (self.delegate && [self.delegate respondsToSelector:@selector(inkTopToolBar:tag:isSelect:)]) {
  108. [self.delegate inkTopToolBar:self tag:(CPDFInkTopToolBarSelect)button.tag isSelect:button.isSelected];
  109. }
  110. ((UIButton *)self.buttonArray[button.tag]).backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  111. }
  112. break;
  113. case CPDFInkTopToolBarRedo: {
  114. if (self.delegate && [self.delegate respondsToSelector:@selector(inkTopToolBar:tag:isSelect:)]) {
  115. [self.delegate inkTopToolBar:self tag:(CPDFInkTopToolBarSelect)button.tag isSelect:button.isSelected];
  116. }
  117. ((UIButton *)self.buttonArray[button.tag]).backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  118. }
  119. break;
  120. case CPDFInkTopToolBarClear: {
  121. if (self.delegate && [self.delegate respondsToSelector:@selector(inkTopToolBar:tag:isSelect:)]) {
  122. [self.delegate inkTopToolBar:self tag:(CPDFInkTopToolBarSelect)button.tag isSelect:button.isSelected];
  123. }
  124. [self removeFromSuperview];
  125. }
  126. break;
  127. case CPDFInkTopToolBarSave:{
  128. if (self.delegate && [self.delegate respondsToSelector:@selector(inkTopToolBar:tag:isSelect:)]) {
  129. [self.delegate inkTopToolBar:self tag:(CPDFInkTopToolBarSelect)button.tag isSelect:button.isSelected];
  130. }
  131. [self removeFromSuperview];
  132. }
  133. break;
  134. }
  135. }
  136. @end