123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- //
- // PDFBottomToolbar.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 "PDFBottomToolbar.h"
- #import "PDFViewerModeViewController.h"
- @interface PDFBottomToolbar ()
- @property (nonatomic,retain) UILabel *pageLabel;
- @property (nonatomic,retain) UIButton *bookmarkButton;
- @end
- @implementation PDFBottomToolbar
- #pragma mark - Init Methods
- - (id)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];
- self.layer.borderColor = [UIColor colorWithRed:210.0/255.0 green:210.0/255.0 blue:210.0/255.0 alpha:1.0].CGColor;
- self.layer.borderWidth = 1.0;
-
- UIButton *pervButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [pervButton setImage:[UIImage imageNamed:@"btn_frontpage.png"] forState:UIControlStateNormal];
- [pervButton addTarget:self action:@selector(buttonItemClicked_Previous:) forControlEvents:UIControlEventTouchUpInside];
- pervButton.frame = CGRectMake(0, 0, 50, frame.size.height);
- [self addSubview:pervButton];
-
- UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [nextButton setImage:[UIImage imageNamed:@"btn_nextpage.png"] forState:UIControlStateNormal];
- [nextButton addTarget:self action:@selector(buttonItemClicked_Next:) forControlEvents:UIControlEventTouchUpInside];
- nextButton.frame = CGRectMake(frame.size.width-50, 0, 50, frame.size.height);
- [self addSubview:nextButton];
-
- UIButton *viewButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [viewButton setImage:[UIImage imageNamed:@"btn_viewer_mode00.png"]forState:UIControlStateNormal];
- [viewButton addTarget:self action:@selector(buttonItemClicked_ViewerMode:) forControlEvents:UIControlEventTouchUpInside];
- viewButton.frame = CGRectMake(50, 0, 50, frame.size.height);
- [self addSubview:viewButton];
-
- _bookmarkButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
- [_bookmarkButton setImage:[UIImage imageNamed:@"btn_bookmark01.png"] forState:UIControlStateNormal];
- [_bookmarkButton setImage:[UIImage imageNamed:@"btn_bookmark02.png"] forState:UIControlStateSelected];
- [_bookmarkButton addTarget:self action:@selector(buttonItemClicked_Bookmark:) forControlEvents:UIControlEventTouchUpInside];
- _bookmarkButton.frame = CGRectMake(frame.size.width-100, 0, 50, frame.size.height);
- [self addSubview:_bookmarkButton];
-
- _pageLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 100, frame.size.height)];
- _pageLabel.font = [UIFont systemFontOfSize:16];
- [_pageLabel setBackgroundColor:[UIColor clearColor]];
- _pageLabel.textAlignment = NSTextAlignmentCenter;
- _pageLabel.textColor = [UIColor colorWithRed:106.0/255.0 green:106.0/255.0 blue:106.0/255.0 alpha:1.0];
- _pageLabel.text = @"0 / 0";
- [self addSubview:_pageLabel];
- }
- return self;
- }
- - (void)dealloc {
- [_bookmarkButton release];
- [_pageLabel release];
- [super dealloc];
- }
- #pragma mark - Public Methods
- - (void)reloadData {
- NSInteger pageIndex = [self.pdfViewController.pdfView currentPageIndex];
- NSInteger pageCount = [self.pdfViewController.pdfView.document pageCount];
- self.pageLabel.text = [NSString stringWithFormat:@"%@ / %@",@(pageIndex+1),@(pageCount)];
- self.bookmarkButton.selected = [self.pdfViewController.pdfView.document bookmarkForPageIndex:pageIndex] ? YES : NO;
- }
- #pragma mark - Button Actions
- - (void)buttonItemClicked_Previous:(UIButton *)button {
- NSInteger pageIndex = [self.pdfViewController.pdfView currentPageIndex];
- if (pageIndex <= 0) {
- pageIndex = 0;
- } else {
- pageIndex--;
- }
- [self.pdfViewController.pdfView goToPageIndex:pageIndex animated:YES];
- }
- - (void)buttonItemClicked_Next:(UIButton *)button {
- NSInteger pageIndex = [self.pdfViewController.pdfView currentPageIndex];
- NSInteger pageCount = [self.pdfViewController.pdfView.document pageCount];
- if (pageIndex >= pageCount-1) {
- pageIndex = pageCount-1;
- } else {
- pageIndex++;
- }
- [self.pdfViewController.pdfView goToPageIndex:pageIndex animated:YES];
- }
- - (void)buttonItemClicked_ViewerMode:(UIButton *)button {
- __block PDFViewerModeViewController *vc = [[PDFViewerModeViewController alloc] init];
- vc.themesType = self.pdfViewController.pdfView.displayMode;
- vc.color = self.pdfViewController.pdfView.displayModeCustomColor;
- vc.brightness = [UIScreen mainScreen].brightness;
- vc.scrollType = self.pdfViewController.pdfView.displayDirection;
- vc.isCropMode = self.pdfViewController.pdfView.displayCrop;
- vc.callback = ^(NSInteger index) {
- if (index == 0) {
- self.pdfViewController.pdfView.displayModeCustomColor = vc.color;
- self.pdfViewController.pdfView.displayMode = vc.themesType;
- [self.pdfViewController.pdfView layoutDocumentView];
- } else if (index == 1) {
- [UIScreen mainScreen].brightness = vc.brightness;
- } else if (index == 2) {
- self.pdfViewController.pdfView.displayDirection = vc.scrollType;
- [self.pdfViewController.pdfView layoutDocumentView];
- } else if (index == 3) {
- self.pdfViewController.view.window.userInteractionEnabled = NO;
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- self.pdfViewController.pdfView.displayCrop = vc.isCropMode;
- dispatch_async(dispatch_get_main_queue(), ^{
- self.pdfViewController.view.window.userInteractionEnabled = YES;
- [self.pdfViewController.pdfView layoutDocumentView];
- });
- });
- }
- };
- CGRect rect = [button.superview convertRect:button.frame toView:self.pdfViewController.view];
- [vc showViewController:self.pdfViewController inRect:rect];
- [vc release];
- }
- - (void)buttonItemClicked_Bookmark:(UIButton *)button {
- NSInteger pageIndex = [self.pdfViewController.pdfView currentPageIndex];
- if ([self.pdfViewController.pdfView.document bookmarkForPageIndex:pageIndex]) {
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Yes", nil)
- style:UIAlertActionStyleDefault
- handler:^(UIAlertAction *action){
- [self.pdfViewController.pdfView.document removeBookmarkForPageIndex:pageIndex];
- [self.pdfViewController.pdfView setNeedsDisplayForVisiblePages];
- self.bookmarkButton.selected = NO;
- }];
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"No", nil)
- style:UIAlertActionStyleCancel
- handler:nil];
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Attention", nil)
- message:NSLocalizedString(@"Do you want to remove old bookmark?", nil)
- preferredStyle:UIAlertControllerStyleAlert];
- [alert addAction:okAction];
- [alert addAction:cancelAction];
- [self.pdfViewController presentViewController:alert animated:YES completion:nil];
- } else {
- NSString *text = [NSString stringWithFormat:NSLocalizedString(@"Page %ld", nil), pageIndex+1];
- [self.pdfViewController.pdfView.document addBookmark:text forPageIndex:pageIndex];
- [self.pdfViewController.pdfView setNeedsDisplayForVisiblePages];
- self.bookmarkButton.selected = YES;
-
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil
- message:NSLocalizedString(@"Bookmark added successfully.", nil)
- preferredStyle:UIAlertControllerStyleAlert];
- [self.pdfViewController presentViewController:alert animated:YES completion:nil];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [alert dismissViewControllerAnimated:YES completion:nil];
- });
- }
- }
- @end
|