StampCollectionViewCell.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //
  2. // StampCollectionViewCell.m
  3. // PDFReader
  4. //
  5. // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // The PDF Reader Sample applications are licensed with a modified BSD license.
  8. // Please see License for details. This notice may not be removed from this file.
  9. //
  10. #import "StampCollectionViewCell.h"
  11. #pragma mark - StampCollectionViewCell
  12. @interface StampCollectionViewCell()
  13. @property (nonatomic,retain) UIButton *selectButton;
  14. @end
  15. @implementation StampCollectionViewCell
  16. - (void)dealloc {
  17. [_stampImage release];
  18. [_selectButton release];
  19. [super dealloc];
  20. }
  21. - (instancetype)initWithFrame:(CGRect)frame {
  22. if (self = [super initWithFrame:frame]) {
  23. _stampImage = [[UIImageView alloc] init];
  24. _stampImage.backgroundColor = [UIColor clearColor];
  25. _stampImage.contentMode = UIViewContentModeScaleAspectFit;
  26. [self.contentView addSubview:self.stampImage];
  27. self.selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
  28. [_selectButton setImage:[UIImage imageNamed:@"btn_unselected.png"] forState:UIControlStateNormal];
  29. [_selectButton setImage:[UIImage imageNamed:@"btn_selected.png"] forState:UIControlStateSelected];
  30. [self.contentView addSubview:_selectButton];
  31. self.selectButton.hidden = YES;
  32. self.contentView.layer.borderWidth = 0.5;
  33. self.contentView.layer.borderColor = [UIColor lightGrayColor].CGColor;
  34. }
  35. return self;
  36. }
  37. - (void)layoutSubviews {
  38. [super layoutSubviews];
  39. _stampImage.frame = CGRectMake(10, (self.contentView.bounds.size.height - 50)/2,
  40. self.contentView.bounds.size.width - 20, 50);
  41. _selectButton.frame = CGRectMake(5, 5, 20, 20);
  42. }
  43. - (void)setEditing:(BOOL)editing {
  44. _editing = editing;
  45. if (_editing) {
  46. self.selectButton.hidden = NO;
  47. } else {
  48. self.selectButton.hidden = YES;
  49. }
  50. }
  51. - (void)setSelected:(BOOL)selected {
  52. [super setSelected:selected];
  53. self.selectButton.selected = self.selected;
  54. }
  55. @end
  56. #pragma mark - StampCollectionHeaderView
  57. @implementation StampCollectionHeaderView
  58. - (void)dealloc {
  59. [_textLabel release];
  60. [super dealloc];
  61. }
  62. - (instancetype)initWithFrame:(CGRect)frame {
  63. if (self = [super initWithFrame:frame]) {
  64. self.backgroundColor = [UIColor colorWithRed:248.0/255.0 green:248.0/255.0 blue:248.0/255.0 alpha:1.0];
  65. _textLabel = [[UILabel alloc] init];
  66. _textLabel.textColor = [UIColor colorWithRed:36.0/255.0 green:36.0/255.0 blue:36.0/255.0 alpha:1.0];
  67. _textLabel.font = [UIFont systemFontOfSize:14.0];
  68. [self addSubview:_textLabel];
  69. }
  70. return self;
  71. }
  72. - (void)layoutSubviews {
  73. [super layoutSubviews];
  74. _textLabel.frame = CGRectMake(10, 0, self.bounds.size.width-20, 20);
  75. }
  76. @end
  77. #pragma mark - StampCollectionHeaderView1
  78. @interface StampCollectionHeaderView1()
  79. @property (nonatomic,retain) UIView * headerView;
  80. @property (nonatomic,retain) UIButton * textButton;
  81. @property (nonatomic,retain) UIButton * imageButton;
  82. @end
  83. @implementation StampCollectionHeaderView1
  84. - (void)dealloc {
  85. [_headerView release];
  86. [_textButton release];
  87. [_imageButton release];
  88. [_textLabel release];
  89. [super dealloc];
  90. }
  91. - (instancetype)initWithFrame:(CGRect)frame {
  92. if (self = [super initWithFrame:frame]) {
  93. _headerView = [[UIView alloc] init];
  94. _headerView.backgroundColor = [UIColor clearColor];
  95. [self addSubview:_headerView];
  96. self.textButton = [UIButton buttonWithType:UIButtonTypeSystem];
  97. [_textButton setTitle:NSLocalizedString(@"New Text Stamp", nil) forState:UIControlStateNormal];
  98. [_textButton setTitleColor:[UIColor colorWithRed:36.0/255.0 green:36.0/255.0 blue:36.0/255.0 alpha:1.0] forState:UIControlStateNormal];
  99. [_textButton addTarget:self action:@selector(buttonItemClicked_AddText:) forControlEvents:UIControlEventTouchUpInside];
  100. _textButton.layer.borderWidth = 1;
  101. _textButton.layer.cornerRadius = 5;
  102. _textButton.titleLabel.font = [UIFont systemFontOfSize:16.0];
  103. _textButton.titleLabel.adjustsFontSizeToFitWidth = YES;
  104. _textButton.layer.borderColor = [UIColor colorWithRed:17.0/255.0 green:140.0/255.0 blue:1.0 alpha:1.0].CGColor;
  105. [_headerView addSubview:_textButton];
  106. self.imageButton = [UIButton buttonWithType:UIButtonTypeSystem];
  107. [_imageButton setTitle:NSLocalizedString(@"New Image Stamp", nil) forState:UIControlStateNormal];
  108. [_imageButton setTitleColor:[UIColor colorWithRed:36.0/255.0 green:36.0/255.0 blue:36.0/255.0 alpha:1.0] forState:UIControlStateNormal];
  109. _imageButton.titleLabel.font = [UIFont systemFontOfSize:16.0];
  110. _imageButton.titleLabel.adjustsFontSizeToFitWidth = YES;
  111. [_imageButton addTarget:self action:@selector(buttonItemClicked_AddImage:) forControlEvents:UIControlEventTouchUpInside];
  112. _imageButton.layer.borderWidth = 1;
  113. _imageButton.layer.cornerRadius = 5;
  114. _imageButton.layer.borderColor = [UIColor colorWithRed:17.0/255.0 green:140.0/255.0 blue:1.0 alpha:1.0].CGColor;
  115. [_headerView addSubview:_imageButton];
  116. self.backgroundColor = [UIColor colorWithRed:248.0/255.0 green:248.0/255.0 blue:248.0/255.0 alpha:1.0];
  117. _textLabel = [[UILabel alloc] init];
  118. _textLabel.textColor = [UIColor colorWithRed:36.0/255.0 green:36.0/255.0 blue:36.0/255.0 alpha:1.0];
  119. _textLabel.font = [UIFont systemFontOfSize:14.0];
  120. [self addSubview:_textLabel];
  121. }
  122. return self;
  123. }
  124. - (void)layoutSubviews {
  125. [super layoutSubviews];
  126. _headerView.frame = CGRectMake(0, 0, self.bounds.size.width, 80);
  127. _textButton.frame = CGRectMake(10, CGRectGetMinY(_headerView.frame)+10, (self.bounds.size.width-40)/2, 60);
  128. _imageButton.frame = CGRectMake(30 + (self.bounds.size.width-40)/2, CGRectGetMinY(_headerView.frame)+10, (self.bounds.size.width-40)/2, 60);
  129. _textLabel.frame = CGRectMake(10, CGRectGetMinY(_headerView.frame)+80, self.bounds.size.width-20, 20);
  130. }
  131. #pragma mark - Button Event Action
  132. - (void)buttonItemClicked_AddImage:(id)sender {
  133. if ([self.delegate respondsToSelector:@selector(addImageWithHeaderView:)]) {
  134. [self.delegate addImageWithHeaderView:self];
  135. }
  136. }
  137. - (void)buttonItemClicked_AddText:(id)sender {
  138. if ([self.delegate respondsToSelector:@selector(addTextWithHeaderView:)]) {
  139. [self.delegate addTextWithHeaderView:self];
  140. }
  141. }
  142. @end