CStampShapView.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // CStampShapView.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 "CStampShapView.h"
  13. #if __has_include(<ComPDFKit_Tools/ComPDFKit_Tools.h>)
  14. #import <ComPDFKit_Tools/CPDFColorUtils.h>
  15. #else
  16. #import "CPDFColorUtils.h"
  17. #endif
  18. @interface CStampShapView ()
  19. @property (nonatomic, strong) UILabel *titleLabel;
  20. @property (nonatomic, strong) UIButton *centerButton;
  21. @property (nonatomic, strong) UIButton *leftButton;
  22. @property (nonatomic, strong) UIButton *rightButton;
  23. @property (nonatomic, strong) UIButton *noneButton;
  24. @property (nonatomic, strong) UIView *shapeView;
  25. @property (nonatomic, strong) NSMutableArray *buttonArray;
  26. @end
  27. @implementation CStampShapView
  28. #pragma mark - Initializers
  29. - (instancetype)initWithFrame:(CGRect)frame {
  30. if (self = [super initWithFrame:frame]) {
  31. self.titleLabel = [[UILabel alloc] init];
  32. self.titleLabel.text = NSLocalizedString(@"Style", nil);
  33. self.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
  34. self.titleLabel.textColor = [UIColor grayColor];
  35. self.titleLabel.font = [UIFont systemFontOfSize:12.0];
  36. [self addSubview:self.titleLabel];
  37. self.shapeView = [[UIView alloc] initWithFrame:CGRectMake(0, 30, self.bounds.size.width, 60)];
  38. [self addSubview:self.shapeView];
  39. self.buttonArray = [NSMutableArray array];
  40. self.centerButton = [[UIButton alloc] init];
  41. [self.centerButton setImage:[UIImage imageNamed:@"CPDFStampTextImageCenter" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  42. [self.centerButton addTarget:self action:@selector(buttonItemClicked_select:) forControlEvents:UIControlEventTouchUpInside];
  43. self.centerButton.tag = 0;
  44. self.centerButton.layer.cornerRadius = 5.0;
  45. self.centerButton.layer.masksToBounds = YES;
  46. [self.shapeView addSubview:self.centerButton];
  47. [self.buttonArray addObject:self.centerButton];
  48. self.centerButton.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  49. self.leftButton = [[UIButton alloc] init];
  50. [self.leftButton setImage:[UIImage imageNamed:@"CPDFStampTextImageLeft" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  51. [self.leftButton addTarget:self action:@selector(buttonItemClicked_select:) forControlEvents:UIControlEventTouchUpInside];
  52. self.leftButton.tag = 1;
  53. self.leftButton.layer.cornerRadius = 5.0;
  54. self.leftButton.layer.masksToBounds = YES;
  55. [self.shapeView addSubview:self.leftButton];
  56. [self.buttonArray addObject:self.leftButton];
  57. self.rightButton = [[UIButton alloc] init];
  58. [self.rightButton setImage:[UIImage imageNamed:@"CPDFStampTextImageRight" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  59. [self.rightButton addTarget:self action:@selector(buttonItemClicked_select:) forControlEvents:UIControlEventTouchUpInside];
  60. self.rightButton.tag = 2;
  61. self.rightButton.layer.cornerRadius = 5.0;
  62. self.rightButton.layer.masksToBounds = YES;
  63. [self.shapeView addSubview:self.rightButton];
  64. [self.buttonArray addObject:self.rightButton];
  65. self.noneButton = [[UIButton alloc] init];
  66. [self.noneButton setImage:[UIImage imageNamed:@"CPDFStampTextImageNone" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  67. [self.noneButton addTarget:self action:@selector(buttonItemClicked_select:) forControlEvents:UIControlEventTouchUpInside];
  68. self.noneButton.tag = 3;
  69. self.noneButton.layer.cornerRadius = 5.0;
  70. self.noneButton.layer.masksToBounds = YES;
  71. [self.shapeView addSubview:self.noneButton];
  72. [self.buttonArray addObject:self.noneButton];
  73. }
  74. return self;
  75. }
  76. - (void)layoutSubviews {
  77. [super layoutSubviews];
  78. self.titleLabel.frame = CGRectMake(20, 0, 50, self.bounds.size.height/3);
  79. self.shapeView.frame = CGRectMake(0, self.bounds.size.height/3, self.bounds.size.width, (self.bounds.size.height/3)*2);
  80. self.centerButton.frame = CGRectMake((self.shapeView.bounds.size.width - (44*4))/5, (self.shapeView.bounds.size.height-44)/2, 44, 44);
  81. self.leftButton.frame = CGRectMake(((self.shapeView.bounds.size.width - (44*4))/5)*2 + 44, (self.shapeView.bounds.size.height-44)/2, 44, 44);
  82. self.rightButton.frame = CGRectMake(((self.shapeView.bounds.size.width - (44*4))/5)*3 + 44*2, (self.shapeView.bounds.size.height-44)/2, 44, 44);
  83. self.noneButton.frame = CGRectMake(((self.shapeView.bounds.size.width - (44*4))/5)*4 + 44*3, (self.shapeView.bounds.size.height-44)/2, 44, 44);
  84. }
  85. #pragma mark - Action
  86. - (void)buttonItemClicked_select:(UIButton *)button {
  87. for (int j = 0; j < self.buttonArray.count; j++) {
  88. ((UIButton *)self.buttonArray[j]).backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  89. }
  90. ((UIButton *)self.buttonArray[button.tag]).backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  91. if (self.delegate && [self.delegate respondsToSelector:@selector(stampShapView:tag:)]) {
  92. [self.delegate stampShapView:self tag:button.tag];
  93. }
  94. }
  95. @end