123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- //
- // StampCollectionViewCell.m
- // PDFReader
- //
- // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
- //
- // The PDF Reader Sample applications are licensed with a modified BSD license.
- // Please see License for details. This notice may not be removed from this file.
- //
- #import "StampCollectionViewCell.h"
- #pragma mark - StampCollectionViewCell
- @interface StampCollectionViewCell()
- @property (nonatomic,retain) UIButton *selectButton;
- @end
- @implementation StampCollectionViewCell
- - (void)dealloc {
- [_stampImage release];
- [_selectButton release];
- [super dealloc];
- }
- - (instancetype)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- _stampImage = [[UIImageView alloc] init];
- _stampImage.backgroundColor = [UIColor clearColor];
- _stampImage.contentMode = UIViewContentModeScaleAspectFit;
- [self.contentView addSubview:self.stampImage];
-
- self.selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [_selectButton setImage:[UIImage imageNamed:@"btn_unselected.png"] forState:UIControlStateNormal];
- [_selectButton setImage:[UIImage imageNamed:@"btn_selected.png"] forState:UIControlStateSelected];
- [self.contentView addSubview:_selectButton];
- self.selectButton.hidden = YES;
-
- self.contentView.layer.borderWidth = 0.5;
- self.contentView.layer.borderColor = [UIColor lightGrayColor].CGColor;
- }
- return self;
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
- _stampImage.frame = CGRectMake(10, (self.contentView.bounds.size.height - 50)/2,
- self.contentView.bounds.size.width - 20, 50);
- _selectButton.frame = CGRectMake(5, 5, 20, 20);
- }
- - (void)setEditing:(BOOL)editing {
- _editing = editing;
- if (_editing) {
- self.selectButton.hidden = NO;
- } else {
- self.selectButton.hidden = YES;
- }
- }
- - (void)setSelected:(BOOL)selected {
- [super setSelected:selected];
- self.selectButton.selected = self.selected;
- }
- @end
- #pragma mark - StampCollectionHeaderView
- @implementation StampCollectionHeaderView
- - (void)dealloc {
- [_textLabel release];
- [super dealloc];
- }
- - (instancetype)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- self.backgroundColor = [UIColor colorWithRed:248.0/255.0 green:248.0/255.0 blue:248.0/255.0 alpha:1.0];
- _textLabel = [[UILabel alloc] init];
- _textLabel.textColor = [UIColor colorWithRed:36.0/255.0 green:36.0/255.0 blue:36.0/255.0 alpha:1.0];
- _textLabel.font = [UIFont systemFontOfSize:14.0];
- [self addSubview:_textLabel];
- }
- return self;
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
- _textLabel.frame = CGRectMake(10, 0, self.bounds.size.width-20, 20);
- }
- @end
- #pragma mark - StampCollectionHeaderView1
- @interface StampCollectionHeaderView1()
- @property (nonatomic,retain) UIView * headerView;
- @property (nonatomic,retain) UIButton * textButton;
- @property (nonatomic,retain) UIButton * imageButton;
- @end
- @implementation StampCollectionHeaderView1
- - (void)dealloc {
- [_headerView release];
- [_textButton release];
- [_imageButton release];
- [_textLabel release];
- [super dealloc];
- }
- - (instancetype)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- _headerView = [[UIView alloc] init];
- _headerView.backgroundColor = [UIColor clearColor];
- [self addSubview:_headerView];
-
- self.textButton = [UIButton buttonWithType:UIButtonTypeSystem];
- [_textButton setTitle:NSLocalizedString(@"New Text Stamp", nil) forState:UIControlStateNormal];
- [_textButton setTitleColor:[UIColor colorWithRed:36.0/255.0 green:36.0/255.0 blue:36.0/255.0 alpha:1.0] forState:UIControlStateNormal];
- [_textButton addTarget:self action:@selector(buttonItemClicked_AddText:) forControlEvents:UIControlEventTouchUpInside];
- _textButton.layer.borderWidth = 1;
- _textButton.layer.cornerRadius = 5;
- _textButton.titleLabel.font = [UIFont systemFontOfSize:16.0];
- _textButton.titleLabel.adjustsFontSizeToFitWidth = YES;
- _textButton.layer.borderColor = [UIColor colorWithRed:17.0/255.0 green:140.0/255.0 blue:1.0 alpha:1.0].CGColor;
- [_headerView addSubview:_textButton];
-
- self.imageButton = [UIButton buttonWithType:UIButtonTypeSystem];
- [_imageButton setTitle:NSLocalizedString(@"New Image Stamp", nil) forState:UIControlStateNormal];
- [_imageButton setTitleColor:[UIColor colorWithRed:36.0/255.0 green:36.0/255.0 blue:36.0/255.0 alpha:1.0] forState:UIControlStateNormal];
- _imageButton.titleLabel.font = [UIFont systemFontOfSize:16.0];
- _imageButton.titleLabel.adjustsFontSizeToFitWidth = YES;
- [_imageButton addTarget:self action:@selector(buttonItemClicked_AddImage:) forControlEvents:UIControlEventTouchUpInside];
- _imageButton.layer.borderWidth = 1;
- _imageButton.layer.cornerRadius = 5;
- _imageButton.layer.borderColor = [UIColor colorWithRed:17.0/255.0 green:140.0/255.0 blue:1.0 alpha:1.0].CGColor;
- [_headerView addSubview:_imageButton];
-
- self.backgroundColor = [UIColor colorWithRed:248.0/255.0 green:248.0/255.0 blue:248.0/255.0 alpha:1.0];
-
- _textLabel = [[UILabel alloc] init];
- _textLabel.textColor = [UIColor colorWithRed:36.0/255.0 green:36.0/255.0 blue:36.0/255.0 alpha:1.0];
- _textLabel.font = [UIFont systemFontOfSize:14.0];
- [self addSubview:_textLabel];
-
- }
- return self;
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
- _headerView.frame = CGRectMake(0, 0, self.bounds.size.width, 80);
- _textButton.frame = CGRectMake(10, CGRectGetMinY(_headerView.frame)+10, (self.bounds.size.width-40)/2, 60);
- _imageButton.frame = CGRectMake(30 + (self.bounds.size.width-40)/2, CGRectGetMinY(_headerView.frame)+10, (self.bounds.size.width-40)/2, 60);
- _textLabel.frame = CGRectMake(10, CGRectGetMinY(_headerView.frame)+80, self.bounds.size.width-20, 20);
- }
- #pragma mark - Button Event Action
- - (void)buttonItemClicked_AddImage:(id)sender {
- if ([self.delegate respondsToSelector:@selector(addImageWithHeaderView:)]) {
- [self.delegate addImageWithHeaderView:self];
- }
- }
- - (void)buttonItemClicked_AddText:(id)sender {
- if ([self.delegate respondsToSelector:@selector(addTextWithHeaderView:)]) {
- [self.delegate addTextWithHeaderView:self];
- }
- }
- @end
|