// // PDFViewerModeViewController.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 "PDFViewerModeViewController.h" #import "PDFSettingsColorViewController.h" #import @interface PDFViewerModeViewController () @property (nonatomic,assign) IBOutlet UIScrollView *scrollView; @property (nonatomic,assign) IBOutlet UISlider *slider; @property (nonatomic,assign) IBOutlet UISegmentedControl *segmentedControl; @property (nonatomic,assign) IBOutlet UISwitch *switchButton; @end @implementation PDFViewerModeViewController #pragma mark - Init Methods - (void)dealloc { Block_release(_callback); [_color release]; [super dealloc]; } #pragma mark - UIViewController Methods - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. self.preferredContentSize = CGSizeMake(320, 270); NSArray *colors = @[[UIColor whiteColor], [UIColor blackColor], [UIColor colorWithRed:255/255.0 green:239/255.0 blue:190/255.0 alpha:1.0], [UIColor colorWithRed:153.0/255.0 green:207.0/255.0 blue:161.0/255.0 alpha:1.0], [UIColor clearColor]]; for (NSInteger i = 0; i < [colors count]; i++) { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button addTarget:self action:@selector(buttonItemClicked_Color:) forControlEvents:UIControlEventTouchUpInside]; button.tag = i; button.frame = CGRectMake(15+i*60, 5, 50.0, 50.0); button.layer.masksToBounds = YES; button.layer.cornerRadius = button.frame.size.width * 0.5; button.layer.borderWidth = 2.0; button.layer.borderColor = ((UIColor *)colors[i]).CGColor; button.showsTouchWhenHighlighted = YES; [button setBackgroundColor:colors[i]]; if (i == self.themesType) { button.layer.borderColor = [UIColor colorWithRed:73.0/255.0 green:106.0/255.0 blue:239.0/255.0 alpha:1.0].CGColor; } if (i == [colors count]-1) { [button setBackgroundImage:[UIImage imageNamed:@"view_color_wheel_img.png"] forState:UIControlStateNormal]; } [self.scrollView addSubview:button]; } self.slider.value = self.brightness; self.segmentedControl.selectedSegmentIndex = self.scrollType; self.switchButton.on = self.isCropMode; } #pragma mark - Button Action - (void)buttonItemClicked_Color:(UIButton *)button { if (![[CPDFKit sharedInstance] allowsFeature:CPDFKitFeatureViewerRender]) { UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleCancel handler:nil]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:NSLocalizedString(@"Your license does not support this feature, please upgrade your license privilege.", nil) preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:cancelAction]; [self presentViewController:alert animated:YES completion:nil]; return; } if (button.tag == 4) { CGRect rect = [self.view convertRect:button.frame fromView:button.superview]; __block PDFSettingsColorViewController *vc = [[PDFSettingsColorViewController alloc] init]; [vc setColor:self.color]; vc.callback = ^{ self.color = vc.color; for (UIButton *button in self.scrollView.subviews) { if ([button isKindOfClass:[UIButton class]]) { button.layer.borderColor = button.backgroundColor.CGColor; } } button.layer.borderColor = [UIColor colorWithRed:73.0/255.0 green:106.0/255.0 blue:239.0/255.0 alpha:1.0].CGColor; self.themesType = button.tag; if (self.callback) { self.callback(0); } }; [vc showViewController:self inRect:rect]; [vc release]; } else { for (UIButton *button in self.scrollView.subviews) { if ([button isKindOfClass:[UIButton class]]) { button.layer.borderColor = button.backgroundColor.CGColor; } } button.layer.borderColor = [UIColor colorWithRed:73.0/255.0 green:106.0/255.0 blue:239.0/255.0 alpha:1.0].CGColor; self.themesType = button.tag; if (self.callback) { self.callback(0); } } } - (IBAction)sliderValueChanged_Brightness:(id)sender { self.brightness = self.slider.value; if (self.callback) { self.callback(1); } } - (IBAction)segmentedControlValueChanged_Mode:(id)sender { self.scrollType = self.segmentedControl.selectedSegmentIndex; if (self.callback) { self.callback(2); } } - (IBAction)switchValueChanged_CropMode:(id)sender { self.isCropMode = self.switchButton.isOn; if (self.callback) { self.callback(3); } } #pragma mark - Public Methods - (void)showViewController:(UIViewController *)viewController inBarButtonItem:(UIBarButtonItem *)barButtonItem { self.modalPresentationStyle = UIModalPresentationPopover; UIPopoverPresentationController *popVC = self.popoverPresentationController; popVC.delegate = self; popVC.barButtonItem = barButtonItem; popVC.permittedArrowDirections = UIPopoverArrowDirectionUp; [viewController presentViewController:self animated:YES completion:nil]; } - (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