// // PDFShapeViewController.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 "PDFShapeViewController.h" #import "ColorView.h" @interface PDFShapeViewController () @property (nonatomic,assign) IBOutlet UIView *contentView; @property (nonatomic,assign) IBOutlet ColorView *colorView; @property (nonatomic,assign) IBOutlet UISegmentedControl *segmentedControl; @property (nonatomic,assign) IBOutlet UISlider *opacitySlider; @property (nonatomic,assign) IBOutlet UISlider *thicknessSlider; @property (nonatomic,assign) IBOutlet UILabel *opacityMinLabel; @property (nonatomic,assign) IBOutlet UIButton *style1Button; @property (nonatomic,assign) IBOutlet UIButton *style2Button; @property (nonatomic,assign) IBOutlet UIButton *style3Button; @property (nonatomic,assign) IBOutlet UIButton *style4Button; @property (nonatomic,retain) UIView *styleSelectedView; @end @implementation PDFShapeViewController #pragma mark Init Methods - (void)dealloc { Block_release(_callback); [_styleSelectedView release]; [_color release]; [_fillColor release]; [super dealloc]; } #pragma mark View Methods - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. _styleSelectedView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; _styleSelectedView.backgroundColor = [UIColor lightGrayColor]; _styleSelectedView.layer.masksToBounds = YES; _styleSelectedView.layer.cornerRadius = 5; [self.view addSubview:_styleSelectedView]; __block __typeof(self) blockSelf = self; self.colorView.callback = ^(UIColor *color) { if (blockSelf.segmentedControl.selectedSegmentIndex == 0) { blockSelf.color = color; } else { blockSelf.fillColor = color; } if (blockSelf.callback) { blockSelf.callback(); } }; self.colorView.allowsClearColor = YES; self.thicknessSlider.value = self.borderWidth; [self updateSelectedView]; } - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; if (self.allowsShowStyle) { self.preferredContentSize = CGSizeMake(300, self.contentView.bounds.size.height); } else { self.preferredContentSize = CGSizeMake(300, self.contentView.bounds.size.height-78); } UIButton *button = nil; if (self.style == 0) { button = self.style1Button; } else if (self.style == 1) { button = self.style2Button; } else if (self.style == 2) { button = self.style3Button; } else if (self.style == 3) { button = self.style4Button; } self.styleSelectedView.center = CGPointMake(button.center.x, button.frame.origin.y-self.styleSelectedView.bounds.size.height/2.0); } - (void)updateSelectedView { if (self.segmentedControl.selectedSegmentIndex == 0) { self.colorView.color = self.color; } else { self.colorView.color = self.fillColor; } if (self.segmentedControl.selectedSegmentIndex == 0) { self.opacitySlider.minimumValue = 25; self.opacitySlider.maximumValue = 100; self.opacitySlider.value = self.opacity; self.opacityMinLabel.text = @"25%"; } else { self.opacitySlider.minimumValue = 0; self.opacitySlider.maximumValue = 100; self.opacitySlider.value = self.fillOpacity; self.opacityMinLabel.text = @"0%"; } } #pragma mark - Button Actions - (IBAction)segmentedControlValueChanged_Mode:(id)sender { [self updateSelectedView]; } - (IBAction)buttonItemClicked_Style:(UIButton *)button { self.style = button.tag; self.styleSelectedView.center = CGPointMake(button.center.x, button.frame.origin.y-self.styleSelectedView.bounds.size.height/2.0); if (self.callback) { self.callback(); } } - (IBAction)sliderValueChanged_Opacity:(UISlider *)slider { if (self.segmentedControl.selectedSegmentIndex == 0) { self.opacity = slider.value; } else { self.fillOpacity = slider.value; } if (self.callback) { self.callback(); } } - (IBAction)sliderValueChanged_BorderWidth:(UISlider *)slider { self.borderWidth = slider.value; if (self.callback) { self.callback(); } } #pragma mark - Public Methods - (void)showViewController:(UIViewController *)viewController inRect:(CGRect)rect { self.modalPresentationStyle = UIModalPresentationPopover; UIPopoverPresentationController *popVC = self.popoverPresentationController; popVC.delegate = self; popVC.sourceRect = rect; popVC.sourceView = viewController.view; [viewController presentViewController:self animated:YES completion:nil]; } #pragma mark - UIPopoverPresentationControllerDelegate - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection { return UIModalPresentationNone; } @end