123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- //
- // PDFFreehandView.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 "PDFFreehandView.h"
- #import <ComPDFKit/ComPDFKit.h>
- #import "PDFFreehandViewController.h"
- @interface PDFFreehandView ()
- @property (nonatomic,retain) UIView *colorView;
- @end
- @implementation PDFFreehandView
- #pragma mark - Super Method
- - (instancetype)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- self.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0];
- self.layer.borderColor = [UIColor colorWithRed:170.0/255.0 green:170.0/255.0 blue:170.0/255.0 alpha:1.0].CGColor;
- self.layer.borderWidth = 1.0;
- self.layer.cornerRadius = 5.0;
-
- CGFloat width = frame.size.width/6;
- CGFloat height = frame.size.height;
-
- UIButton *undoButton = [UIButton buttonWithType:UIButtonTypeCustom];
- undoButton.tag = 0;
- undoButton.frame = CGRectMake(0, 0, width, height);
- [undoButton setImage:[UIImage imageNamed:@"btn_undo.png"] forState:UIControlStateNormal];
- [undoButton addTarget:self action:@selector(buttonItemClicked_Switch:) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:undoButton];
-
- UIButton *redoButton = [UIButton buttonWithType:UIButtonTypeCustom];
- redoButton.tag = 1;
- redoButton.frame = CGRectMake(width, 0, width, height);
- [redoButton setImage:[UIImage imageNamed:@"btn_redo.png"] forState:UIControlStateNormal];
- [redoButton addTarget:self action:@selector(buttonItemClicked_Switch:) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:redoButton];
-
- UIButton *eraseButton = [UIButton buttonWithType:UIButtonTypeCustom];
- eraseButton.tag = 2;
- eraseButton.frame = CGRectMake(2*width, 0, width, height);
- [eraseButton setImage:[UIImage imageNamed:@"btn_eraser_00.png"] forState:UIControlStateNormal];
- [eraseButton setImage:[UIImage imageNamed:@"btn_eraser_01.png"] forState:UIControlStateSelected];
- [eraseButton addTarget:self action:@selector(buttonItemClicked_Switch:) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:eraseButton];
-
- UIButton *propertyButton = [UIButton buttonWithType:UIButtonTypeCustom];
- propertyButton.tag = 3;
- propertyButton.frame = CGRectMake(3*width, 0, width, height);
- [propertyButton setImage:[UIImage imageNamed:@"btn_brush_a00.png"] forState:UIControlStateNormal];
- [propertyButton addTarget:self action:@selector(buttonItemClicked_Switch:) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:propertyButton];
-
- _colorView = [[UIView alloc] initWithFrame:CGRectMake((width-8)/2.0, 6, 8, 8)];
- _colorView.layer.cornerRadius = _colorView.bounds.size.width/2.0;
- _colorView.backgroundColor = CPDFKitShareConfig.freehandAnnotationColor;
- [propertyButton addSubview:_colorView];
-
- UIButton *clearButton = [UIButton buttonWithType:UIButtonTypeSystem];
- clearButton.tag = 4;
- clearButton.frame = CGRectMake(4*width, 0, width, height);
- [clearButton setTitle:NSLocalizedString(@"Clear", nil) forState:UIControlStateNormal];
- [clearButton setTitleColor:[UIColor colorWithRed:243.0/255.0 green:0 blue:8.0/255.0 alpha:1.0] forState:UIControlStateNormal];
- clearButton.titleLabel.font = [UIFont systemFontOfSize:15.0];
- [clearButton addTarget:self action:@selector(buttonItemClicked_Switch:) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:clearButton];
-
- UIButton *saveButton = [UIButton buttonWithType:UIButtonTypeSystem];
- saveButton.tag = 5;
- saveButton.frame = CGRectMake(5*width, 0, width, height);
- [saveButton setTitle:NSLocalizedString(@"Done", nil) forState:UIControlStateNormal];
- [saveButton setTitleColor:[UIColor colorWithRed:41.0/255.0 green:111.0/255.0 blue:173.0/255.0 alpha:1.0] forState:UIControlStateNormal];
- saveButton.titleLabel.font = [UIFont systemFontOfSize:15.0];
- [saveButton addTarget:self action:@selector(buttonItemClicked_Switch:) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:saveButton];
- }
- return self;
- }
- - (void)dealloc {
- Block_release(_callback);
- [_colorView release];
- [super dealloc];
- }
- #pragma mark - Button Actions
- - (void)buttonItemClicked_Switch:(UIButton *)button {
- if (button.tag == 3) {
- __block PDFFreehandViewController *vc = [[PDFFreehandViewController alloc] init];
- vc.color = CPDFKitShareConfig.freehandAnnotationColor;
- vc.opacity = CPDFKitShareConfig.freehandAnnotationOpacity;
- vc.borderWidth = CPDFKitShareConfig.freehandAnnotationBorderWidth;
- vc.callback = ^{
- if (self.callback) {
- self.callback(button.tag, button.isSelected);
- }
- self.colorView.backgroundColor = vc.color;
- CPDFKitShareConfig.freehandAnnotationColor = vc.color;
- CPDFKitShareConfig.freehandAnnotationOpacity = vc.opacity;
- CPDFKitShareConfig.freehandAnnotationBorderWidth = vc.borderWidth;
- };
- UIViewController *viewController = [UIApplication sharedApplication].keyWindow.rootViewController;
- CGRect rect = [button.superview convertRect:button.frame toView:viewController.view];
- [vc showViewController:viewController inRect:rect];
- [vc release];
- } else {
- if (button.tag == 2) {
- button.selected = !button.isSelected;
- if (button.isSelected) {
- button.backgroundColor = [UIColor lightGrayColor];
- } else {
- button.backgroundColor = [UIColor clearColor];
- }
- }
- if (self.callback) {
- self.callback(button.tag, button.isSelected);
- }
- }
- }
- @end
|